Merge pull request #10450 from poettering/foreach-line-excorcism
FOREACH_LINE excorcism
This commit is contained in:
@@ -985,10 +985,9 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi
|
||||
|
||||
int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char line[LINE_MAX];
|
||||
const char *fs, *controller_str;
|
||||
int unified, r;
|
||||
size_t cs = 0;
|
||||
int unified;
|
||||
|
||||
assert(path);
|
||||
assert(pid >= 0);
|
||||
@@ -1018,10 +1017,15 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
|
||||
|
||||
(void) __fsetlocking(f, FSETLOCKING_BYCALLER);
|
||||
|
||||
FOREACH_LINE(line, f, return -errno) {
|
||||
for (;;) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
char *e, *p;
|
||||
|
||||
truncate_nl(line);
|
||||
r = read_line(f, LONG_LINE_MAX, &line);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
if (unified) {
|
||||
e = startswith(line, "0:");
|
||||
|
||||
+10
-2
@@ -13,6 +13,7 @@
|
||||
#include <libmount.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "def.h"
|
||||
#include "escape.h"
|
||||
#include "extract-word.h"
|
||||
#include "fd-util.h"
|
||||
@@ -954,8 +955,8 @@ int mount_option_mangle(
|
||||
|
||||
int dev_is_devtmpfs(void) {
|
||||
_cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
|
||||
char line[LINE_MAX], *e;
|
||||
int mount_id, r;
|
||||
char *e;
|
||||
|
||||
r = path_get_mnt_id("/dev", &mount_id);
|
||||
if (r < 0)
|
||||
@@ -967,9 +968,16 @@ int dev_is_devtmpfs(void) {
|
||||
|
||||
(void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER);
|
||||
|
||||
FOREACH_LINE(line, proc_self_mountinfo, return -errno) {
|
||||
for (;;) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
int mid;
|
||||
|
||||
r = read_line(proc_self_mountinfo, LONG_LINE_MAX, &line);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
if (sscanf(line, "%i", &mid) != 1)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "architecture.h"
|
||||
#include "def.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
@@ -514,8 +515,8 @@ int get_process_exe(pid_t pid, char **name) {
|
||||
|
||||
static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char line[LINE_MAX];
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
assert(field);
|
||||
assert(uid);
|
||||
@@ -533,9 +534,16 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
|
||||
|
||||
(void) __fsetlocking(f, FSETLOCKING_BYCALLER);
|
||||
|
||||
FOREACH_LINE(line, f, return -errno) {
|
||||
for (;;) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
char *l;
|
||||
|
||||
r = read_line(f, LONG_LINE_MAX, &line);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
l = strstrip(line);
|
||||
|
||||
if (startswith(l, field)) {
|
||||
|
||||
+11
-4
@@ -14,6 +14,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "def.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
@@ -1222,6 +1223,7 @@ int get_timezones(char ***ret) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_strv_free_ char **zones = NULL;
|
||||
size_t n_zones = 0, n_allocated = 0;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
@@ -1234,13 +1236,18 @@ int get_timezones(char ***ret) {
|
||||
|
||||
f = fopen("/usr/share/zoneinfo/zone.tab", "re");
|
||||
if (f) {
|
||||
char l[LINE_MAX];
|
||||
|
||||
FOREACH_LINE(l, f, return -errno) {
|
||||
for (;;) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
char *p, *w;
|
||||
size_t k;
|
||||
|
||||
p = strstrip(l);
|
||||
r = read_line(f, LONG_LINE_MAX, &line);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
p = strstrip(line);
|
||||
|
||||
if (isempty(p) || *p == '#')
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user