diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-02-11 08:13:14 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-02-11 08:13:14 +0000 |
commit | 2f8984613e17f9e5971ec338240b0bb6d2dd1cc6 (patch) | |
tree | 4061a64dc5ee8c415ca249ec1852cfc666e1468b /src/minutils/s6-swapoff.c | |
parent | 3caba3fd8f3825544c065ec62e4298c6edc76b28 (diff) | |
download | s6-linux-utils-2f8984613e17f9e5971ec338240b0bb6d2dd1cc6.tar.xz |
Code refactor; only s6-ps has remaining globals now
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/minutils/s6-swapoff.c')
-rw-r--r-- | src/minutils/s6-swapoff.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/minutils/s6-swapoff.c b/src/minutils/s6-swapoff.c deleted file mode 100644 index 00df142..0000000 --- a/src/minutils/s6-swapoff.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <sys/types.h> -#include <sys/swap.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/buffer.h> -#include <skalibs/strerr.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> -#include <skalibs/skamisc.h> - -#define USAGE "s6-swapoff device <or> s6-swapoff -a" - -#define BUFSIZE 4095 - -static int swapoffall ( ) -{ - char buf[BUFSIZE+1] ; - buffer b ; - stralloc sa = STRALLOC_ZERO ; - int e = 0 ; - int r ; - int fd = open_readb("/proc/swaps") ; - if (fd < 0) strerr_diefu1sys(111, "open_readb /proc/swaps") ; - buffer_init(&b, &buffer_read, fd, buf, BUFSIZE+1) ; - if (skagetln(&b, &sa, '\n') < 0) strerr_diefu1sys(111, "skagetln") ; - for (;;) - { - size_t n ; - sa.len = 0 ; - r = skagetln(&b, &sa, '\n') ; - if (r < 0) strerr_diefu1sys(111, "skagetln") ; - if (!r) break ; - n = byte_chr(sa.s, sa.len, ' ') ; - if (n >= sa.len) strerr_dief1x(111, "invalid line in /proc/swaps") ; - sa.s[n] = 0 ; - if (swapoff(sa.s) < 0) { e++ ; strerr_warnwu2sys("swapoff ", sa.s) ; } - } - fd_close(fd) ; - stralloc_free(&sa) ; - return e ; -} - -int main (int argc, char const *const *argv) -{ - PROG = "s6-swapoff" ; - if (argc < 2) strerr_dieusage(100, USAGE) ; - if ((argv[1][0] == '-') && (argv[1][1] == 'a') && !argv[1][2]) - return swapoffall() ; - if (swapoff(argv[1]) == -1) strerr_diefu2sys(111, "swapoff ", argv[1]) ; - return 0 ; -} |