8 * Copyright (C) 1996-99 Andre M. Hedrick <andre@suse.com>
9 * Copyright (C) 1999-2000 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General
13 * Public License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 * If this is a Windows machine, we do NOT create a pid file.
30 * We prevent multiple copies of apcupsd from running by
31 * ensuring that there is only one system tray entry for
36 * Create a file in `path'. Used for nologin and powerfail
39 int make_file(UPSINFO
*ups
, const char *path
)
43 if ((makefd
= open(path
, O_CREAT
| O_WRONLY
, 0644)) >= 0) {
46 log_event(ups
, LOG_ERR
, "Unable to create %s: ERR=%s\n",
47 path
, strerror(errno
));
53 /* Create the pid lock file. */
54 const char *pidfile
= APCPID
;
55 void make_pid_file(void)
57 #if !defined(HAVE_WIN32)
63 if ((pfd
= open(pidfile
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0644)) >= 0) {
64 len
= asnprintf(buf
, sizeof(buf
), "%ld\n", (long)pid
);