summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/path.h1
-rw-r--r--lib/path.c22
-rw-r--r--sys-utils/choom.c2
3 files changed, 24 insertions, 1 deletions
diff --git a/include/path.h b/include/path.h
index b34aa366e..8dadef1d0 100644
--- a/include/path.h
+++ b/include/path.h
@@ -110,6 +110,7 @@ int ul_path_write_string(struct path_cxt *pc, const char *str, const char *path)
int ul_path_writef_string(struct path_cxt *pc, const char *str, const char *path, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
+int ul_path_write_s64(struct path_cxt *pc, int64_t num, const char *path);
int ul_path_write_u64(struct path_cxt *pc, uint64_t num, const char *path);
int ul_path_writef_u64(struct path_cxt *pc, uint64_t num, const char *path, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
diff --git a/lib/path.c b/lib/path.c
index d36fe41e8..9dfdc94f8 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -850,6 +850,28 @@ int ul_path_writef_string(struct path_cxt *pc, const char *str, const char *path
return ul_path_write_string(pc, str, p);
}
+int ul_path_write_s64(struct path_cxt *pc, int64_t num, const char *path)
+{
+ char buf[sizeof(stringify_value(LLONG_MAX))];
+ int rc, errsv;
+ int fd, len;
+
+ fd = ul_path_open(pc, O_WRONLY|O_CLOEXEC, path);
+ if (fd < 0)
+ return -errno;
+
+ len = snprintf(buf, sizeof(buf), "%" PRId64, num);
+ if (len < 0 || (size_t) len >= sizeof(buf))
+ rc = len < 0 ? -errno : -E2BIG;
+ else
+ rc = write_all(fd, buf, len);
+
+ errsv = errno;
+ close(fd);
+ errno = errsv;
+ return rc;
+}
+
int ul_path_write_u64(struct path_cxt *pc, uint64_t num, const char *path)
{
char buf[sizeof(stringify_value(ULLONG_MAX))];
diff --git a/sys-utils/choom.c b/sys-utils/choom.c
index 6895aef43..eff95b6bf 100644
--- a/sys-utils/choom.c
+++ b/sys-utils/choom.c
@@ -74,7 +74,7 @@ static int get_score_adj(struct path_cxt *pc)
static int set_score_adj(struct path_cxt *pc, int adj)
{
- return ul_path_write_u64(pc, adj, "oom_score_adj");
+ return ul_path_write_s64(pc, adj, "oom_score_adj");
}
int main(int argc, char **argv)