/*
- * $Id$ */
+ * $Id$
* Latest:
- * http://cvs.jankratochvil.net/viewcvs/*checkout*/nethome/src/inetdmx.c?rev=HEAD
+ * http://cvs.jankratochvil.net/viewcvs/nethome/src/inetdmx.c?rev=HEAD
*
* 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
opt_start_command_timeout,opt_port,opt_command);
}
-/* Returns: Is fresh? */
-static int lock_create_and_time_check(int lock_mode)
+/* Returns: Is fresh or does not exist? */
+static int lock_open_and_time_check(int lock_mode)
{
struct stat statbuf;
if (!opt_lock)
return 0;
+ if (access(opt_lock,R_OK|W_OK)) {
+ if (errno==ENOENT)
+ return 1;
+ fatal("Error checking existance of the lock file \"%s\": %m",opt_lock);
+ }
if (!lock_create(lock_mode|LOCK_NB))
- exit(EXIT_SUCCESS);
+ return 0;
if (lock_fd==-1 || fstat(lock_fd,&statbuf))
fatal("Error fstat(2)ting lock file \"%s\": %m",opt_lock);
return statbuf.st_mtime>=time(NULL)-opt_idle_server_timeout;
if (opt_idle_server_timeout!=DEFAULT_IDLE_SERVER_TIMEOUT && !opt_lock)
fatal("-l|--lock is a required argument for -i|--idle-server-timeout of -1|--start");
- is_fresh=lock_create_and_time_check(LOCK_SH);
+ is_fresh=lock_open_and_time_check(LOCK_SH);
lock_close();
if (is_fresh)
exit(EXIT_SUCCESS);
- lock_create_and_time_check(LOCK_EX);
+ lock_open_and_time_check(LOCK_EX);
system_checked(opt_command);
lock_delete_and_close();