tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: rc.d and non daemon servers
On Wed, Mar 04, 2009 at 09:33:36PM -0500, Steven M. Bellovin wrote:
> On Wed, 4 Mar 2009 16:57:35 -0500
> "Steven M. Bellovin" <smb%cs.columbia.edu@localhost> wrote:
>
> > On Wed, 4 Mar 2009 15:15:00 -0500
> > Amitai Schlair <schmonz%schmonz.com@localhost> wrote:
> >
> > > http://libslack.org/daemon/
> >
> > Interesting, but it's rather, umm, large... Thanks. I may still
> > write my own.
> >
> OK, here it is. It's dumb and stupid, and does nothing but invoke our
> daemon() subroutine. If folks care, I'll write a man page and stick it
> into pkgsrc. Usage should be obvious from the code and daemon(3).
The following changes are taken from the nit department:
Use a static function for usage message
Use standard exit values where possible
Use getopt(3)
and perhaps a license could be placed on the code so that people know
where they stand with it.
Thanks for doing this.
Best wishes,
Alistair
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void
usage(const char *prog)
{
(void) fprintf(stderr, "Usage: %s: [-c] [-f] [-h] command [args]\n",
prog);
}
int
main(int argc, char *argv[])
{
int nochdir;
int noclose;
int i;
nochdir = 0;
noclose = 0;
while ((i = getopt(argc, argv, "cfh")) != -1) {
switch(i) {
case 'c':
nochdir = 1;
break;
case 'f':
noclose = 1;
break;
case 'h':
usage(*argv);
exit(EXIT_SUCCESS);
default:
usage(*argv);
exit(EXIT_FAILURE);
}
}
if (optind == argc) {
usage(*argv);
return 2;
}
if (daemon(nochdir, noclose) != 0) {
perror("daemon");
return 3;
}
execvp(argv[optind], &argv[optind]);
perror("exec");
return 4;
}
Home |
Main Index |
Thread Index |
Old Index