New code should be using /run. So pretend to be new.
Signed-off-by: NeilBrown <neilb@suse.de>
required. It obeys the wakeup_count protocol to get race-free
suspend and allows clients to register to find out about
suspend and to block it either briefly or longer term.
- It uses files in /var/run/suspend for all communication.
+ It uses files in /run/suspend for all communication.
File are:
services to client.
lsused (which needs a better name) listens on the socket
- /var/run/suspend/registration
+ /run/suspend/registration
A client may connect and send a list of file descriptors.
When a suspend is immanent, if any file descriptor is readable,
lsused will send a 'S' message to the client and await an 'R' reply
wakealarmd:
This allows clients to register on the socket.
- /var/run/suspend/wakealarm
+ /run/suspend/wakealarm
They write a timestamp in seconds since epoch, and will receive
a 'Now' message when that time arrives.
Between the time the connection is made and the time a "seconds"
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
block_suspend() {
- exec 9< /var/run/suspend/disabled
+ exec 9< /run/suspend/disabled
flock --shared 9
}
int fd;
char zero = 0;
- fd = open("/var/run/suspend/watching-next",
+ fd = open("/run/suspend/watching-next",
O_RDWR|O_CREAT|O_TRUNC, 0640);
if (fd < 0)
return;
close(fd);
- fd = open("/var/run/suspend/watching",
+ fd = open("/run/suspend/watching",
O_RDWR|O_CREAT|O_TRUNC, 0640);
if (fd < 0)
return;
int fd;
char zero[2];
- fd = open("/var/run/suspend/watching", O_RDWR|O_CREAT, 0640);
+ fd = open("/run/suspend/watching", O_RDWR|O_CREAT, 0640);
if (fd < 0)
return;
- rename("/var/run/suspend/watching-next",
- "/var/run/suspend/watching");
+ rename("/run/suspend/watching-next",
+ "/run/suspend/watching");
zero[0] = zero[1] = 0;
write(fd, zero, 2);
close(fd);
* If the 'immediate' file is not locked, we remove
* and ignore it as the requesting process has died
*/
- int fd = open("/var/run/suspend/immediate", O_RDWR);
+ int fd = open("/run/suspend/immediate", O_RDWR);
if (fd >= 0) {
if (flock(fd, LOCK_EX|LOCK_NB) == 0) {
/* we got the lock, so owner must have died */
- unlink("/var/run/suspend/immediate");
+ unlink("/run/suspend/immediate");
close(fd);
} else {
/* Still valid */
return 1;
}
}
- fd = open("/var/run/suspend/request", O_RDONLY);
+ fd = open("/run/suspend/request", O_RDONLY);
if (fd < 0)
return 0;
close(fd);
int dir;
int disable;
- mkdir("/var/run/suspend", 0770);
+ mkdir("/run/suspend", 0770);
- dir = open("/var/run/suspend", O_RDONLY);
- disable = open("/var/run/suspend/disabled", O_RDWR|O_CREAT, 0640);
+ dir = open("/run/suspend", O_RDONLY);
+ disable = open("/run/suspend/disabled", O_RDWR|O_CREAT, 0640);
if (dir < 0 || disable < 0)
exit(1);
struct stat stb;
/* Don't accept an old request */
- unlink("/var/run/suspend/request");
+ unlink("/run/suspend/request");
wait_request(dir);
if (flock(disable, LOCK_EX|LOCK_NB) != 0) {
flock(disable, LOCK_EX);
flock(disable, LOCK_UN);
- unlink("/var/run/suspend/request");
+ unlink("/run/suspend/request");
/* blocked - so need to ensure request still valid */
continue;
}
* shared lock on the suspend/disabled file and then read the event.
*
* The client opens connects on a unix domain socket to
- * /var/run/suspend/registration
+ * /run/suspend/registration
* It sets 'W' with some fds attached to be watched.
* On notification if any fds are readable we send by 'S' to say
* Suspend Soon and wait for 'R' to say 'Ready'.
s = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, "/var/run/suspend/registration");
- unlink("/var/run/suspend/registration");
+ strcpy(addr.sun_path, "/run/suspend/registration");
+ unlink("/run/suspend/registration");
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
exit(1);
listen(s, 20);
main(int argc, char *argv[])
{
- int dirfd = open("/var/run/suspend", O_RDONLY);
- int fd_request = open("/var/run/suspend/request",
+ int dirfd = open("/run/suspend", O_RDONLY);
+ int fd_request = open("/run/suspend/request",
O_RDWR|O_CREAT, 0640);
- int fd_watching = open("/var/run/suspend/watching", O_RDONLY);
+ int fd_watching = open("/run/suspend/watching", O_RDONLY);
if (fd_request < 0)
exit(2);
if (fstat(fd_request, &stat) != 0
|| stat.st_nlink == 0) {
struct stat s1, s2;
- int fd_watching2 = open("/var/run/suspend/watching",
+ int fd_watching2 = open("/run/suspend/watching",
O_RDONLY);
if (fd_watching < 0 ||
fd_watching2 < 0 ||
/*
* susman - manage suspend
* This daemon forks and runs three processes
- * - one which manages suspend based on files in /var/run/suspend
+ * - one which manages suspend based on files in /run/suspend
* - one which listens on a socket and handles suspend requests that way,
* - one which provides a wakeup service using the RTC alarm.
*
"""
global lock_watcher
if not lock_watcher:
- lock_watcher = dnotify.dir('/var/run/suspend')
+ lock_watcher = dnotify.dir('/run/suspend')
- self.f = open('/var/run/suspend/watching', 'r')
+ self.f = open('/run/suspend/watching', 'r')
self.getlock()
while os.fstat(self.f.fileno()).st_nlink == 0:
self.f.close()
- self.f = open('/var/run/suspend/watching', 'r')
+ self.f = open('/run/suspend/watching', 'r')
self.getlock()
self.suspended = False
if self.suspended:
# resume has happened if watching-next has been renamed.
if (os.fstat(self.f.fileno()).st_ino ==
- os.stat('/var/run/suspend/watching').st_ino):
+ os.stat('/run/suspend/watching').st_ino):
global lock_watcher
self.suspended = False
self.watch.cancel()
# ready for suspend
global lock_watcher
old = self.f
- self.f = open('/var/run/suspend/watching-next', 'r')
+ self.f = open('/run/suspend/watching-next', 'r')
self.getlock()
self.suspended = True
self.watch.cancel()
if on:
if self.immediate_fd:
return
- self.immediate_fd = open('/var/run/suspend/immediate','w')
+ self.immediate_fd = open('/run/suspend/immediate','w')
fcntl.flock(self.immediate_fd, fcntl.LOCK_EX)
return
else:
class blocker:
def __init__(self, blocked = True):
- self.blockfd = open('/var/run/suspend/disabled')
+ self.blockfd = open('/run/suspend/disabled')
if blocked:
self.block()
def block(self):
def abort_cycle():
- fd = open('/var/run/suspend/disabled')
+ fd = open('/run/suspend/disabled')
fd.read(1)
fd.close()
int suspend_open()
{
- return open("/var/run/suspend/disabled", O_RDONLY|O_CLOEXEC);
+ return open("/run/suspend/disabled", O_RDONLY|O_CLOEXEC);
}
int suspend_block(int handle)
goto abort;
addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, "/var/run/suspend/wakealarm");
+ strcpy(addr.sun_path, "/run/suspend/wakealarm");
if (connect(h->sock, (struct sockaddr*)&addr, sizeof(addr)) != 0)
goto abort;
s = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, "/var/run/suspend/wakealarm");
- unlink("/var/run/suspend/wakealarm");
+ strcpy(addr.sun_path, "/run/suspend/wakealarm");
+ unlink("/run/suspend/wakealarm");
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
exit(2);
listen(s, 20);
if (h->sock < 0 || h->disable < 0)
goto abort;
addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, "/var/run/suspend/registration");
+ strcpy(addr.sun_path, "/run/suspend/registration");
if (connect(h->sock, (struct sockaddr*)&addr, sizeof(addr)) != 0)
goto abort;
return;
/* We need to move on now. */
- fd = open("/var/run/suspend/watching-next", O_RDONLY|O_CLOEXEC);
+ fd = open("/run/suspend/watching-next", O_RDONLY|O_CLOEXEC);
flock(fd, LOCK_SH);
han->nextfd = fd;
rv = han->will_suspend(han->data);
han->nextfd = -1;
signal_set(&han->ev, SIGIO, checkdir, han);
signal_add(&han->ev, NULL);
- han->dirfd = open("/var/run/suspend", O_RDONLY|O_CLOEXEC);
+ han->dirfd = open("/run/suspend", O_RDONLY|O_CLOEXEC);
if (han->dirfd < 0)
goto abort;
fcntl(han->dirfd, F_NOTIFY, DN_MODIFY | DN_MULTISHOT);
again:
- fd = open("/var/run/suspend/watching", O_RDONLY|O_CLOEXEC);
+ fd = open("/run/suspend/watching", O_RDONLY|O_CLOEXEC);
flock(fd, LOCK_SH);
han->fd = fd;
checkdir(0, 0, han);