SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I've been practicing C programming the past month and had the idea to do this. I don't know if there's already something similar, or if anyone would find this program useful.
Slervice simply calls Pat's scripts and the chmod command. I believe it's self explanatory. It can be compiled with
cc slervice.c -o slervice
Code:
// slervice.c
//
// Copyright 2011 Andy Alt <andyqwerty removeit users.sourceforge.net>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define VER "0.01.1a"
#define DATED "March 23, 2011"
int main(int argc, char **argv)
{
printf("\nslervice %s %s\n\n", VER, DATED);
if (argc != 3) {
printf("Usage: slervice <service> <start,restart,disable,enable>\n");
printf("Ex: slervice httpd restart\n");
exit(1);
}
char cmd[256];
if (strcmp(argv[2],"enable") == 0) {
strcpy(cmd,"chmod -v +x /etc/rc.d/rc.");
strcat(cmd,argv[1]);
}
else if (strcmp(argv[2],"disable") == 0) {
strcpy(cmd,"chmod -v -x /etc/rc.d/rc.");
strcat(cmd,argv[1]);
}
else {
strcpy(cmd, "/etc/rc.d/rc.");
strcat(cmd, argv[1]);
strcat(cmd, " ");
strcat(cmd, argv[2]);
}
printf("Executing %s\n", cmd);
system(cmd);
return 0;
}
The simplicity of the task seems to negate the need in efficiency from using a compiled program. Not to say that the program isn't nice or useful. It is.
But the execution of services are already using bash scripts anyway. What's one more execution of another short lived shell to execute a wrapper script to execute the service script?
Shell script is definitely the right tool for this sort of job, I was under the impression that Andy was just doing this as a C coding learning exercise though.
The simplicity of the task seems to negate the need in efficiency from using a compiled program. Not to say that the program isn't nice or useful. It is.
Thank you.
Quote:
But the execution of services are already using bash scripts anyway. What's one more execution of another short lived shell to execute a wrapper script to execute the service script?
As GazL mentioned, it was a learning exercise.
I had another idea regarding the service startup scripts. Allow me to illustrate in a diff manner:
err... sorry... I miss things in posts sometimes. Either way, looked like a great opportunity in messing with c-strings... I hate those things. But then... it helps to have a better understanding of pointers as well.
I just hate the whole
const char "string" vs. pointer to 's''t''r''i''n''g''\0'
I had another idea regarding the service startup scripts. Allow me to illustrate in a diff manner:
I can see where you're going with that, and it's kind of an interesting concept. it sort of gives the service scripts a sort of object orientated feel, and you could add all sorts of features for various services. An install/setup call for rc.mysql for example.
However, the way to UNIX enlightenment is to "Do one thing and do it well". Admin assistants/wizards and front ends really don't belong in the service startup/shutdown scripts which really ought to be kept as simple as possible. if one must have them at all, then they should be invoked from front end programs such as your 'service' program, or Richard's bash script, or even bigger interfaces such as SUSE's YAST.
Debian used to have this sort of functionality built into their packages(they probably still do, but it's been years since I tried debian), You used to do something like "dpkg --reconfigure" and it'd do setup type stuff related to that package. I never really liked that sort of thing though.
lumak, no apologies necessary. Not only do I also miss stuff sometimes, but if I added up all the things I did wrong in my life, it might wind up being a long int (unsigned).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.