utils.c (a957cbc02531a23beeac6dd9e751f8d4dadaf7a9) utils.c (272ced2556e63943113a54c113f8c11aeb53a5c3)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
4 */
5
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
4 */
5
6#define _GNU_SOURCE
6#include <dirent.h>
7#include <stdarg.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include <ctype.h>
12#include <errno.h>
13#include <fcntl.h>

--- 132 unchanged lines hidden (view full) ---

146 return 0;
147
148err:
149 debug_msg("Error parsing the cpu list %s", cpu_list);
150 return 1;
151}
152
153/*
7#include <dirent.h>
8#include <stdarg.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12#include <ctype.h>
13#include <errno.h>
14#include <fcntl.h>

--- 132 unchanged lines hidden (view full) ---

147 return 0;
148
149err:
150 debug_msg("Error parsing the cpu list %s", cpu_list);
151 return 1;
152}
153
154/*
155 * parse_cpu_set - parse a cpu_list filling cpu_set_t argument
156 *
157 * Receives a cpu list, like 1-3,5 (cpus 1, 2, 3, 5), and then set
158 * filling cpu_set_t argument.
159 *
160 * Returns 1 on success, 0 otherwise.
161 */
162int parse_cpu_set(char *cpu_list, cpu_set_t *set)
163{
164 const char *p;
165 int end_cpu;
166 int nr_cpus;
167 int cpu;
168 int i;
169
170 CPU_ZERO(set);
171
172 nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
173
174 for (p = cpu_list; *p; ) {
175 cpu = atoi(p);
176 if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
177 goto err;
178
179 while (isdigit(*p))
180 p++;
181 if (*p == '-') {
182 p++;
183 end_cpu = atoi(p);
184 if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
185 goto err;
186 while (isdigit(*p))
187 p++;
188 } else
189 end_cpu = cpu;
190
191 if (cpu == end_cpu) {
192 debug_msg("cpu_set: adding cpu %d\n", cpu);
193 CPU_SET(cpu, set);
194 } else {
195 for (i = cpu; i <= end_cpu; i++) {
196 debug_msg("cpu_set: adding cpu %d\n", i);
197 CPU_SET(i, set);
198 }
199 }
200
201 if (*p == ',')
202 p++;
203 }
204
205 return 0;
206err:
207 debug_msg("Error parsing the cpu set %s\n", cpu_list);
208 return 1;
209}
210
211/*
154 * parse_duration - parse duration with s/m/h/d suffix converting it to seconds
155 */
156long parse_seconds_duration(char *val)
157{
158 char *end;
159 long t;
160
161 t = strtol(val, &end, 10);

--- 555 unchanged lines hidden ---
212 * parse_duration - parse duration with s/m/h/d suffix converting it to seconds
213 */
214long parse_seconds_duration(char *val)
215{
216 char *end;
217 long t;
218
219 t = strtol(val, &end, 10);

--- 555 unchanged lines hidden ---