2 * Create the suspend-request file, then wait for it to be deleted.
4 * Copyright (C) 2011 Neil Brown <neilb@suse.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 static void catch(int sig)
32 main(int argc, char *argv[])
34 int dirfd = open("/run/suspend", O_RDONLY);
35 int fd_request = open("/run/suspend/request",
36 O_RDWR|O_CREAT, 0640);
37 int fd_watching = open("/run/suspend/watching", O_RDONLY);
50 sigaddset(&set, SIGIO);
52 sigprocmask(SIG_BLOCK, &set, &oldset);
55 fcntl(dirfd, F_NOTIFY, DN_DELETE);
57 if (fstat(fd_request, &stat) != 0
58 || stat.st_nlink == 0) {
60 int fd_watching2 = open("/run/suspend/watching",
62 if (fd_watching < 0 ||
64 fstat(fd_watching, &s1) < 0 ||
65 fstat(fd_watching2, &s2) < 0)
66 /* something strange */
68 if (s1.st_ino == s2.st_ino)
69 /* Didn't suspend - someone must be
77 sigprocmask(SIG_UNBLOCK, &set, &oldset);