From bc336bd45448b5761967792c416d56f84536e95a Mon Sep 17 00:00:00 2001 From: short <> Date: Tue, 9 Aug 2005 20:23:52 +0000 Subject: [PATCH] Fixed --stop if the lock file does not exist. Fixed broken compilation due to the recently inserted comment lines. --- inetdmx.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/inetdmx.c b/inetdmx.c index 40554a5..99077b9 100644 --- a/inetdmx.c +++ b/inetdmx.c @@ -1,7 +1,7 @@ /* - * $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 @@ -470,16 +470,21 @@ int retry; 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; @@ -506,12 +511,12 @@ int is_fresh; 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(); -- 1.8.3.1