mirror of
https://github.com/troglobit/libite.git
synced 2026-11-06 15:50:57 +00:00
pidfile(): Use utimensat() to update atime+mtime
This patch update the `-lite` patch to OpenBSD `pidfile()` by changing the update atime+mtime patch from writing the PID again to instead use utimensat(). Less overhead and nanosecond resolution. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
ac41fa70aa
commit
979f76aea7
1 file changed
+13
-2
@@ -1,3 +1,4 @@
|
|||||||
|
/* Updated by troglobit for libite/finit/uftpd projects 2016/03/19 */
|
||||||
/* $OpenBSD: pidfile.c,v 1.11 2015/06/03 02:24:36 millert Exp $ */
|
/* $OpenBSD: pidfile.c,v 1.11 2015/06/03 02:24:36 millert Exp $ */
|
||||||
/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
|
/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/stat.h> /* utimensat() */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
@@ -50,16 +52,26 @@ int
|
|||||||
pidfile(const char *basename)
|
pidfile(const char *basename)
|
||||||
{
|
{
|
||||||
int save_errno;
|
int save_errno;
|
||||||
|
int atexit_already;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (basename == NULL)
|
if (basename == NULL)
|
||||||
basename = __progname;
|
basename = __progname;
|
||||||
|
|
||||||
|
pid = getpid();
|
||||||
|
atexit_already = 0;
|
||||||
|
|
||||||
if (pidfile_path != NULL) {
|
if (pidfile_path != NULL) {
|
||||||
|
if (0) { //pid == pidfile_pid) {
|
||||||
|
printf("Updating mtime ...\n");
|
||||||
|
utimensat(0, pidfile_path, NULL, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
free(pidfile_path);
|
free(pidfile_path);
|
||||||
pidfile_path = NULL;
|
pidfile_path = NULL;
|
||||||
__pidfile_name = NULL;
|
__pidfile_name = NULL;
|
||||||
|
atexit_already = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _PATH_VARRUN includes trailing / */
|
/* _PATH_VARRUN includes trailing / */
|
||||||
@@ -74,7 +86,6 @@ pidfile(const char *basename)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = getpid();
|
|
||||||
if (fprintf(f, "%ld\n", (long)pid) <= 0 || fflush(f) != 0) {
|
if (fprintf(f, "%ld\n", (long)pid) <= 0 || fflush(f) != 0) {
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
(void) fclose(f);
|
(void) fclose(f);
|
||||||
@@ -90,7 +101,7 @@ pidfile(const char *basename)
|
|||||||
* LITE extension, no need to set up another atexit() handler
|
* LITE extension, no need to set up another atexit() handler
|
||||||
* if user only called us to update the mtime of the PID file
|
* if user only called us to update the mtime of the PID file
|
||||||
*/
|
*/
|
||||||
if (pidfile_pid == pid)
|
if (atexit_already)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
pidfile_pid = pid;
|
pidfile_pid = pid;
|
||||||
|
|||||||
Reference in new issue
Block a user