a daemon. This prevents library functions (such as getopt) stuffing up
our protocol stream when errors are detected.
- defer the error message from the options parsing until after the
socket is multiplexed. This allows clients sending new options which
the remote server doesn't understand to get a sensible error message.
carried across */
orig_umask = (int)umask(0);
- parse_arguments(argc, argv);
+ if (!parse_arguments(argc, argv)) {
+ exit_cleanup(1);
+ }
argc -= optind;
argv += optind;
{"port", 1, 0, OPT_PORT},
{0,0,0,0}};
-void parse_arguments(int argc, char *argv[])
+
+int parse_arguments(int argc, char *argv[])
{
int opt;
int option_index;
preserve_hard_links=1;
#else
rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
- exit_cleanup(1);
+ return 0;
#endif
break;
break;
default:
- /* rprintf(FERROR,"bad option -%c\n",opt); */
- exit_cleanup(1);
+ return 0;
}
}
+ return 1;
}
****************************************************************************/
void become_daemon(void)
{
+ int i;
+
if (fork())
_exit(0);
}
#endif /* TIOCNOTTY */
#endif
- close(0);
- close(1);
- close(2);
+ /* make sure that stdin, stdout an stderr don't stuff things
+ up (library functions, for example) */
+ for (i=0;i<3;i++) {
+ close(i);
+ open("/dev/null", O_RDWR);
+ }
}
/*******************************************************************