Re: dh, the daemon helper
- From: vippstar@xxxxxxxxx
- Date: Fri, 31 Oct 2008 14:31:22 -0700 (PDT)
On Oct 28, 12:27 am, John Kelly <j...@xxxxxxxxxxxx> wrote:
dh, the daemon helper -- run any program or shell command as a daemon.
You can download the C source code, freeely available under the Apache
license, Version 2.0.
ftp://ftp.isp2dial.com/users/jak/src/dh/
Hi John,
I downloaded the source file (dh.c) located in that ftp dir and I have
some comments on your code
First of all, you use perror/exit a lot. I'd write a function/macro if
I were you.
line 43,44 it wouldn't be bad if you had a comment explaining those
magic numbers.
line 52 I think most C programmers prefer const char [] over char
const [] (no actual difference)
line 66,74 that should be isspace((unsigned char)**ts). is* and to*
functions expect a positive integer or EOF, and char may be signed.
line 62-81 can be replaced with keep = strtok(*ts, " \n\t\v\f\r");
if(keep) *ts = keep; strtok(NULL, " \n\t\v\f\r"); with only difference
that it won't behave exactly the same if the implementation has more
than the minimum characters in the space character class. (see IEEE
1003.1, 2004: 7.3.1 LC_CTYPE). Since I don't like either solution I
might've considered to write a map function, and use isspace.
line 143,156 can be replaced with if(lockname[0] == 0). There's no
reason to process the whole string. also line 369
line 155 IMHO the parentheses in the expression &(argv[optind])
should be removed, like: trim(&argv[optind])
I'm curious how your code works since in line 161 you exit if usage is
non-zero, and at that point it can't have the value 0.
I haven't compiled it so I might be missing something.
line 177-213 should be replaced with some loop.
line 214 the cast is not needed. It'd be better if you just had
open_max a long instead of an int though.
line 225-226 change the conversion specifier from u to d and remove
the (unsigned int) cast. There's no benifit.
line 353 you have several memory leaks after this line, since you
do not free the return value of strdup on error.
line 395,395 can be replaced with a simple free(exectemp); free(NULL)
is defined to do nothing.
line 473,478 getpid returns a pid_t, which might not be int (it's
allowed to be any signed integer type). Use printf("%ld",
(long)getpid());
(you won't find any systems that have pid_t's with values bigger than
2^31-1 but LONG_MAX at 2^31-1 - and even then, your process must have
such process id, which would give you implementation-defined behavior
or an implementation-defined signal)
Lastly, I think you're overly verbose with error messages and error
checking.
This is not a complete overview of your code; there might be more
bugs.
HTH
.
- References:
- dh, the daemon helper
- From: John Kelly
- dh, the daemon helper
- Prev by Date: Re: struct stat
- Next by Date: How to handle SIGABRT without stopping the code
- Previous by thread: Re: dh, the daemon helper
- Next by thread: immediately writing serial port buffers
- Index(es):
Relevant Pages
|
Loading