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, 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).
--Steve Bellovin, http://www.cs.columbia.edu/~smb
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
main(int argc, char *argv[])
{
int nochdir, noclose;
char **p;
extern void usage(void);
nochdir = 0; noclose = 0;
for (p = argv+1; *p && **p == '-'; p++) {
if (strcmp(*p, "-c") == 0)
nochdir = 1;
else if (strcmp(*p, "-f") == 0)
noclose = 1;
else if (strcmp(*p, "-h") == 0) {
usage();
return(0);
}
else {
usage();
return 1;
}
}
if (*p == NULL) {
usage();
return 2;
}
if (daemon(nochdir, noclose) != 0) {
perror("daemon");
return 3;
}
execvp(*p, p);
perror("exec");
return 4;
}
void
usage()
{
fprintf(stderr, "Usage: daemond: [-c] [-f] command [args]\n");
}
Home |
Main Index |
Thread Index |
Old Index