|
9 | 9 |
|
10 | 10 | struct confd confd; |
11 | 11 |
|
| 12 | +/* |
| 13 | + * Touch a Finit service .conf file to schedule a synchronized reload. |
| 14 | + * Equivalent to 'initctl touch <svc>' but without the fork+exec overhead. |
| 15 | + * The service name should be given without the .conf suffix. |
| 16 | + */ |
| 17 | +int finit_reload(const char *svc) |
| 18 | +{ |
| 19 | + char path[256]; |
| 20 | + |
| 21 | + /* Prefer the enabled/ symlink -- that's what Finit watches */ |
| 22 | + snprintf(path, sizeof(path), FINIT_RCSD "/enabled/%s.conf", svc); |
| 23 | + if (!utimensat(AT_FDCWD, path, NULL, AT_SYMLINK_NOFOLLOW)) |
| 24 | + return 0; |
| 25 | + |
| 26 | + snprintf(path, sizeof(path), FINIT_RCSD "/available/%s.conf", svc); |
| 27 | + if (!utimensat(AT_FDCWD, path, NULL, AT_SYMLINK_NOFOLLOW)) |
| 28 | + return 0; |
| 29 | + |
| 30 | + ERRNO("failed marking %s for reload", svc); |
| 31 | + return -1; |
| 32 | +} |
| 33 | + |
| 34 | +int finit_reloadf(const char *fmt, ...) |
| 35 | +{ |
| 36 | + char svc[64]; |
| 37 | + va_list ap; |
| 38 | + |
| 39 | + va_start(ap, fmt); |
| 40 | + vsnprintf(svc, sizeof(svc), fmt, ap); |
| 41 | + va_end(ap); |
| 42 | + |
| 43 | + return finit_reload(svc); |
| 44 | +} |
| 45 | + |
| 46 | +int finit_enable(const char *svc) |
| 47 | +{ |
| 48 | + char src[256], dst[256]; |
| 49 | + |
| 50 | + snprintf(src, sizeof(src), FINIT_RCSD "/available/%s.conf", svc); |
| 51 | + snprintf(dst, sizeof(dst), FINIT_RCSD "/enabled/%s.conf", svc); |
| 52 | + if (symlink(src, dst) && errno != EEXIST) { |
| 53 | + ERRNO("failed enabling %s", svc); |
| 54 | + return -1; |
| 55 | + } |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +int finit_disable(const char *svc) |
| 60 | +{ |
| 61 | + char path[256]; |
| 62 | + |
| 63 | + snprintf(path, sizeof(path), FINIT_RCSD "/enabled/%s.conf", svc); |
| 64 | + if (remove(path) && errno != ENOENT) { |
| 65 | + ERRNO("failed disabling %s", svc); |
| 66 | + return -1; |
| 67 | + } |
| 68 | + return 0; |
| 69 | +} |
| 70 | + |
| 71 | +int finit_delete(const char *svc) |
| 72 | +{ |
| 73 | + char path[256]; |
| 74 | + |
| 75 | + snprintf(path, sizeof(path), FINIT_RCSD "/enabled/%s.conf", svc); |
| 76 | + if (remove(path) && errno != ENOENT) { |
| 77 | + ERRNO("failed removing enabled symlink for %s", svc); |
| 78 | + return -1; |
| 79 | + } |
| 80 | + |
| 81 | + snprintf(path, sizeof(path), FINIT_RCSD "/available/%s.conf", svc); |
| 82 | + if (remove(path) && errno != ENOENT) { |
| 83 | + ERRNO("failed removing available conf for %s", svc); |
| 84 | + return -1; |
| 85 | + } |
| 86 | + |
| 87 | + return 0; |
| 88 | +} |
| 89 | + |
| 90 | +int finit_deletef(const char *fmt, ...) |
| 91 | +{ |
| 92 | + char svc[64]; |
| 93 | + va_list ap; |
| 94 | + |
| 95 | + va_start(ap, fmt); |
| 96 | + vsnprintf(svc, sizeof(svc), fmt, ap); |
| 97 | + va_end(ap); |
| 98 | + |
| 99 | + return finit_delete(svc); |
| 100 | +} |
| 101 | + |
| 102 | +int finit_enablef(const char *fmt, ...) |
| 103 | +{ |
| 104 | + char svc[64]; |
| 105 | + va_list ap; |
| 106 | + |
| 107 | + va_start(ap, fmt); |
| 108 | + vsnprintf(svc, sizeof(svc), fmt, ap); |
| 109 | + va_end(ap); |
| 110 | + |
| 111 | + return finit_enable(svc); |
| 112 | +} |
| 113 | + |
| 114 | +int finit_disablef(const char *fmt, ...) |
| 115 | +{ |
| 116 | + char svc[64]; |
| 117 | + va_list ap; |
| 118 | + |
| 119 | + va_start(ap, fmt); |
| 120 | + vsnprintf(svc, sizeof(svc), fmt, ap); |
| 121 | + va_end(ap); |
| 122 | + |
| 123 | + return finit_disable(svc); |
| 124 | +} |
| 125 | + |
12 | 126 |
|
13 | 127 | static int startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *model, |
14 | 128 | const char *xpath, sr_event_t event, unsigned request_id, void *priv) |
@@ -433,7 +547,7 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod |
433 | 547 | client = srx_enabled(session, "/ietf-system:system/ntp/enabled"); |
434 | 548 | server = lydx_get_xpathf(config, "/ietf-ntp:ntp") != NULL; |
435 | 549 |
|
436 | | - systemf("initctl -nbq %s chronyd", client || server ? "enable" : "disable"); |
| 550 | + (client || server) ? finit_enable("chronyd") : finit_disable("chronyd"); |
437 | 551 | } |
438 | 552 |
|
439 | 553 | if (cfg) |
|
0 commit comments