Skip to content

Commit c1b785b

Browse files
authored
Merge pull request systemd#10559 from yuwata/sd-device-prototype-change
sd-device: change prototype of sd_device_get_is_initialized()
2 parents 651b3b6 + 5a937ea commit c1b785b

File tree

10 files changed

+42
-47
lines changed

10 files changed

+42
-47
lines changed

src/libsystemd-network/dhcp-identifier.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i
158158
if (detect_container() <= 0) {
159159
/* not in a container, udev will be around */
160160
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
161-
int initialized, r;
161+
int r;
162162

163163
sprintf(ifindex_str, "n%d", ifindex);
164164
if (sd_device_new_from_device_id(&device, ifindex_str) >= 0) {
165-
r = sd_device_get_is_initialized(device, &initialized);
165+
r = sd_device_get_is_initialized(device);
166166
if (r < 0)
167167
return r;
168-
if (!initialized)
168+
if (r == 0)
169169
/* not yet ready */
170170
return -EBUSY;
171171

src/libsystemd/sd-device/device-enumerator.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
458458
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
459459
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
460460
char syspath[strlen(path) + 1 + strlen(dent->d_name) + 1];
461-
dev_t devnum;
462-
int ifindex, initialized, k;
461+
int initialized, k;
463462

464463
if (dent->d_name[0] == '.')
465464
continue;
@@ -478,9 +477,9 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
478477
continue;
479478
}
480479

481-
k = sd_device_get_is_initialized(device, &initialized);
482-
if (k < 0) {
483-
r = k;
480+
initialized = sd_device_get_is_initialized(device);
481+
if (initialized < 0) {
482+
r = initialized;
484483
continue;
485484
}
486485

@@ -496,8 +495,8 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
496495
*/
497496
if (!enumerator->match_allow_uninitialized &&
498497
!initialized &&
499-
(sd_device_get_devnum(device, &devnum) >= 0 ||
500-
sd_device_get_ifindex(device, &ifindex) >= 0))
498+
(sd_device_get_devnum(device, NULL) >= 0 ||
499+
sd_device_get_ifindex(device, NULL) >= 0))
501500
continue;
502501

503502
if (!match_parent(enumerator, device))

src/libsystemd/sd-device/device-private.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
271271
int r;
272272

273273
assert(device);
274-
assert(mode);
275274

276275
r = device_read_db(device);
277276
if (r < 0)
@@ -280,7 +279,8 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
280279
if (device->devmode == (mode_t) -1)
281280
return -ENOENT;
282281

283-
*mode = device->devmode;
282+
if (mode)
283+
*mode = device->devmode;
284284

285285
return 0;
286286
}
@@ -289,7 +289,6 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
289289
int r;
290290

291291
assert(device);
292-
assert(uid);
293292

294293
r = device_read_db(device);
295294
if (r < 0)
@@ -298,7 +297,8 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
298297
if (device->devuid == (uid_t) -1)
299298
return -ENOENT;
300299

301-
*uid = device->devuid;
300+
if (uid)
301+
*uid = device->devuid;
302302

303303
return 0;
304304
}
@@ -327,7 +327,6 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
327327
int r;
328328

329329
assert(device);
330-
assert(gid);
331330

332331
r = device_read_db(device);
333332
if (r < 0)
@@ -336,7 +335,8 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
336335
if (device->devgid == (gid_t) -1)
337336
return -ENOENT;
338337

339-
*gid = device->devgid;
338+
if (gid)
339+
*gid = device->devgid;
340340

341341
return 0;
342342
}
@@ -726,7 +726,6 @@ int device_get_watch_handle(sd_device *device, int *handle) {
726726
int r;
727727

728728
assert(device);
729-
assert(handle);
730729

731730
r = device_read_db(device);
732731
if (r < 0)
@@ -735,7 +734,8 @@ int device_get_watch_handle(sd_device *device, int *handle) {
735734
if (device->watch_handle < 0)
736735
return -ENOENT;
737736

738-
*handle = device->watch_handle;
737+
if (handle)
738+
*handle = device->watch_handle;
739739

740740
return 0;
741741
}

src/libsystemd/sd-device/sd-device.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
572572
int r;
573573

574574
assert_return(device, -EINVAL);
575-
assert_return(ifindex, -EINVAL);
576575

577576
r = device_read_uevent_file(device);
578577
if (r < 0)
@@ -581,7 +580,8 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
581580
if (device->ifindex <= 0)
582581
return -ENOENT;
583582

584-
*ifindex = device->ifindex;
583+
if (ifindex)
584+
*ifindex = device->ifindex;
585585

586586
return 0;
587587
}
@@ -889,7 +889,6 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
889889
int r;
890890

891891
assert_return(device, -EINVAL);
892-
assert_return(devnum, -EINVAL);
893892

894893
r = device_read_uevent_file(device);
895894
if (r < 0)
@@ -898,7 +897,8 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
898897
if (major(device->devnum) <= 0)
899898
return -ENOENT;
900899

901-
*devnum = device->devnum;
900+
if (devnum)
901+
*devnum = device->devnum;
902902

903903
return 0;
904904
}
@@ -1374,19 +1374,16 @@ static int device_read_db(sd_device *device) {
13741374
return device_read_db_aux(device, false);
13751375
}
13761376

1377-
_public_ int sd_device_get_is_initialized(sd_device *device, int *initialized) {
1377+
_public_ int sd_device_get_is_initialized(sd_device *device) {
13781378
int r;
13791379

13801380
assert_return(device, -EINVAL);
1381-
assert_return(initialized, -EINVAL);
13821381

13831382
r = device_read_db(device);
13841383
if (r < 0)
13851384
return r;
13861385

1387-
*initialized = device->is_initialized;
1388-
1389-
return 0;
1386+
return device->is_initialized;
13901387
}
13911388

13921389
_public_ int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec) {
@@ -1677,7 +1674,6 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
16771674

16781675
assert_return(device, -EINVAL);
16791676
assert_return(key, -EINVAL);
1680-
assert_return(_value, -EINVAL);
16811677

16821678
r = device_properties_prepare(device);
16831679
if (r < 0)
@@ -1687,7 +1683,8 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
16871683
if (!value)
16881684
return -ENOENT;
16891685

1690-
*_value = value;
1686+
if (_value)
1687+
*_value = value;
16911688

16921689
return 0;
16931690
}

src/libsystemd/sd-device/test-sd-device.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void test_sd_device_basic(void) {
2929
assert_se(r >= 0 || r == -ENOENT);
3030

3131
r = sd_device_get_devnum(d, &devnum);
32-
assert_se(r >= 0 || r == -ENOENT);
32+
assert_se((r >= 0 && major(devnum) > 0) || r == -ENOENT);
3333

3434
r = sd_device_get_ifindex(d, &i);
3535
assert_se((r >= 0 && i > 0) || r == -ENOENT);
@@ -47,9 +47,9 @@ static void test_sd_device_basic(void) {
4747
r = sd_device_get_sysnum(d, &val);
4848
assert_se(r >= 0 || r == -ENOENT);
4949

50-
i = 0;
51-
assert_se(sd_device_get_is_initialized(d, &i) >= 0);
52-
if (i > 0) {
50+
r = sd_device_get_is_initialized(d);
51+
assert_se(r >= 0);
52+
if (r > 0) {
5353
r = sd_device_get_usec_since_initialized(d, &usec);
5454
assert_se(r >= 0 || r == -ENODATA);
5555
}

src/libudev/libudev-device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,17 +819,17 @@ _public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_
819819
* Returns: 1 if the device is set up. 0 otherwise.
820820
**/
821821
_public_ int udev_device_get_is_initialized(struct udev_device *udev_device) {
822-
int r, initialized;
822+
int r;
823823

824824
assert_return(udev_device, -EINVAL);
825825

826-
r = sd_device_get_is_initialized(udev_device->device, &initialized);
826+
r = sd_device_get_is_initialized(udev_device->device);
827827
if (r < 0) {
828828
errno = -r;
829829
return 0;
830830
}
831831

832-
return initialized;
832+
return r;
833833
}
834834

835835
/**

src/network/networkd-link.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,8 +3333,8 @@ static int link_load(Link *link) {
33333333
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
33343334
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
33353335
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
3336-
int initialized, r;
33373336
Link *link;
3337+
int r;
33383338

33393339
assert(m);
33403340
assert(m->rtnl);
@@ -3362,12 +3362,12 @@ int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
33623362
goto failed;
33633363
}
33643364

3365-
r = sd_device_get_is_initialized(device, &initialized);
3365+
r = sd_device_get_is_initialized(device);
33663366
if (r < 0) {
33673367
log_link_warning_errno(link, r, "Could not determine whether the device is initialized or not: %m");
33683368
goto failed;
33693369
}
3370-
if (!initialized) {
3370+
if (r == 0) {
33713371
/* not yet ready */
33723372
log_link_debug(link, "link pending udev initialization...");
33733373
return 0;

src/nspawn/nspawn-network.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ int remove_bridge(const char *bridge_name) {
395395
static int parse_interface(const char *name) {
396396
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
397397
char ifi_str[2 + DECIMAL_STR_MAX(int)];
398-
int ifi, initialized, r;
398+
int ifi, r;
399399

400400
ifi = (int) if_nametoindex(name);
401401
if (ifi <= 0)
@@ -406,11 +406,10 @@ static int parse_interface(const char *name) {
406406
if (r < 0)
407407
return log_error_errno(r, "Failed to get device for interface %s: %m", name);
408408

409-
r = sd_device_get_is_initialized(d, &initialized);
409+
r = sd_device_get_is_initialized(d);
410410
if (r < 0)
411411
return log_error_errno(r, "Failed to determine whether interface %s is initialized or not: %m", name);
412-
413-
if (!initialized) {
412+
if (r == 0) {
414413
log_error("Network interface %s is not initialized yet.", name);
415414
return -EBUSY;
416415
}

src/rfkill/rfkill.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ static int wait_for_initialized(
111111
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
112112
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
113113
struct DeviceMonitorData data = {};
114-
int initialized, r;
114+
int r;
115115

116116
assert(device);
117117
assert(ret);
118118

119-
if (sd_device_get_is_initialized(device, &initialized) >= 0 && initialized) {
119+
if (sd_device_get_is_initialized(device) > 0) {
120120
*ret = sd_device_ref(device);
121121
return 0;
122122
}
@@ -152,7 +152,7 @@ static int wait_for_initialized(
152152
return log_full_errno(IN_SET(r, -ENOENT, -ENXIO, -ENODEV) ? LOG_DEBUG : LOG_ERR, r,
153153
"Failed to open device '%s': %m", data.sysname);
154154

155-
if (sd_device_get_is_initialized(d, &initialized) >= 0 && initialized) {
155+
if (sd_device_get_is_initialized(d) > 0) {
156156
*ret = TAKE_PTR(d);
157157
return 0;
158158
}

src/systemd/sd-device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int sd_device_get_devname(sd_device *device, const char **ret);
5959
int sd_device_get_sysname(sd_device *device, const char **ret);
6060
int sd_device_get_sysnum(sd_device *device, const char **ret);
6161

62-
int sd_device_get_is_initialized(sd_device *device, int *initialized);
62+
int sd_device_get_is_initialized(sd_device *device);
6363
int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec);
6464

6565
const char *sd_device_get_tag_first(sd_device *device);

0 commit comments

Comments
 (0)