]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/confile_utils.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
15 #include "confile_utils.h"
20 #include "lxccontainer.h"
22 #include "memory_utils.h"
28 #include "include/strlcpy.h"
31 lxc_log_define(confile_utils
, lxc
);
33 int parse_idmaps(const char *idmap
, char *type
, unsigned long *nsid
,
34 unsigned long *hostid
, unsigned long *range
)
36 __do_free
char *dup
= NULL
;
38 unsigned long tmp_hostid
, tmp_nsid
, tmp_range
;
42 /* Duplicate string. */
45 return ret_errno(ENOMEM
);
47 /* A prototypical idmap entry would be: "u 1000 1000000 65536" */
52 slide
+= strspn(slide
, " \t\r");
53 if (slide
!= window
&& *slide
== '\0')
54 return ret_errno(EINVAL
);
57 if (*slide
!= 'u' && *slide
!= 'g')
58 return log_error_errno(-EINVAL
, EINVAL
, "Invalid id mapping type: %c", *slide
);
63 /* move beyond type */
67 /* Validate that only whitespace follows. */
68 slide
+= strspn(slide
, " \t\r");
69 /* There must be whitespace. */
71 return ret_errno(EINVAL
);
73 /* Mark beginning of nsid. */
75 /* Validate that non-whitespace follows. */
76 slide
+= strcspn(slide
, " \t\r");
77 /* There must be non-whitespace. */
78 if (slide
== window
|| *slide
== '\0')
79 return ret_errno(EINVAL
);
80 /* Mark end of nsid. */
84 ret
= lxc_safe_ulong(window
, &tmp_nsid
);
86 return log_error_errno(ret
, errno
, "Failed to parse nsid: %s", window
);
90 /* Validate that only whitespace follows. */
91 slide
+= strspn(slide
, " \t\r");
92 /* If there was only one whitespace then we whiped it with our \0 above.
93 * So only ensure that we're not at the end of the string.
96 return ret_errno(EINVAL
);
98 /* Mark beginning of hostid. */
100 /* Validate that non-whitespace follows. */
101 slide
+= strcspn(slide
, " \t\r");
102 /* There must be non-whitespace. */
103 if (slide
== window
|| *slide
== '\0')
104 return ret_errno(EINVAL
);
105 /* Mark end of nsid. */
109 ret
= lxc_safe_ulong(window
, &tmp_hostid
);
111 return log_error_errno(ret
, errno
, "Failed to parse hostid: %s", window
);
113 /* Move beyond \0. */
115 /* Validate that only whitespace follows. */
116 slide
+= strspn(slide
, " \t\r");
117 /* If there was only one whitespace then we whiped it with our \0 above.
118 * So only ensure that we're not at the end of the string.
121 return ret_errno(EINVAL
);
123 /* Mark beginning of range. */
125 /* Validate that non-whitespace follows. */
126 slide
+= strcspn(slide
, " \t\r");
127 /* There must be non-whitespace. */
129 return ret_errno(EINVAL
);
131 /* The range is the last valid entry we expect. So make sure that there
132 * is no trailing garbage and if there is, error out.
134 if (*(slide
+ strspn(slide
, " \t\r\n")) != '\0')
135 return ret_errno(EINVAL
);
137 /* Mark end of range. */
141 ret
= lxc_safe_ulong(window
, &tmp_range
);
143 return log_error_errno(ret
, errno
, "Failed to parse id mapping range: %s", window
);
147 *hostid
= tmp_hostid
;
150 /* Yay, we survived. */
154 bool lxc_config_value_empty(const char *value
)
156 if (value
&& strlen(value
) > 0)
162 struct lxc_netdev
*lxc_network_add(struct lxc_list
*networks
, int idx
, bool tail
)
164 __do_free
struct lxc_list
*newlist
= NULL
;
165 __do_free
struct lxc_netdev
*netdev
= NULL
;
167 /* network does not exist */
168 netdev
= malloc(sizeof(*netdev
));
170 return ret_set_errno(NULL
, ENOMEM
);
172 memset(netdev
, 0, sizeof(*netdev
));
173 lxc_list_init(&netdev
->ipv4
);
174 lxc_list_init(&netdev
->ipv6
);
176 /* give network a unique index */
179 /* prepare new list */
180 newlist
= malloc(sizeof(*newlist
));
182 return ret_set_errno(NULL
, ENOMEM
);
184 lxc_list_init(newlist
);
185 newlist
->elem
= netdev
;
188 lxc_list_add_tail(networks
, newlist
);
190 lxc_list_add(networks
, newlist
);
193 return move_ptr(netdev
);
196 /* Takes care of finding the correct netdev struct in the networks list or
197 * allocates a new one if it couldn't be found.
199 struct lxc_netdev
*lxc_get_netdev_by_idx(struct lxc_conf
*conf
,
200 unsigned int idx
, bool allocate
)
202 struct lxc_netdev
*netdev
= NULL
;
203 struct lxc_list
*networks
= &conf
->network
;
204 struct lxc_list
*insert
= networks
;
207 if (!lxc_list_empty(networks
)) {
208 lxc_list_for_each(insert
, networks
) {
209 netdev
= insert
->elem
;
210 if (netdev
->idx
== idx
)
212 else if (netdev
->idx
> idx
)
218 return ret_set_errno(NULL
, EINVAL
);
220 return lxc_network_add(insert
, idx
, true);
223 void lxc_log_configured_netdevs(const struct lxc_conf
*conf
)
225 struct lxc_netdev
*netdev
;
226 struct lxc_list
*it
= (struct lxc_list
*)&conf
->network
;;
228 if ((conf
->loglevel
!= LXC_LOG_LEVEL_TRACE
) &&
229 (lxc_log_get_level() != LXC_LOG_LEVEL_TRACE
))
232 if (lxc_list_empty(it
)) {
233 TRACE("container has no networks configured");
237 lxc_list_for_each(it
, &conf
->network
) {
238 struct lxc_list
*cur
, *next
;
239 struct lxc_inetdev
*inet4dev
;
240 struct lxc_inet6dev
*inet6dev
;
241 char bufinet4
[INET_ADDRSTRLEN
], bufinet6
[INET6_ADDRSTRLEN
];
245 TRACE("index: %zd", netdev
->idx
);
246 TRACE("ifindex: %d", netdev
->ifindex
);
248 switch (netdev
->type
) {
251 TRACE("veth mode: %d", netdev
->priv
.veth_attr
.mode
);
253 if (netdev
->priv
.veth_attr
.pair
[0] != '\0')
254 TRACE("veth pair: %s",
255 netdev
->priv
.veth_attr
.pair
);
257 if (netdev
->priv
.veth_attr
.veth1
[0] != '\0')
259 netdev
->priv
.veth_attr
.veth1
);
261 if (netdev
->priv
.veth_attr
.ifindex
> 0)
262 TRACE("host side ifindex for veth device: %d",
263 netdev
->priv
.veth_attr
.ifindex
);
265 if (netdev
->priv
.veth_attr
.vlan_id_set
)
266 TRACE("veth vlan id: %d", netdev
->priv
.veth_attr
.vlan_id
);
268 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.vlan_tagged_ids
, next
) {
269 unsigned short vlan_tagged_id
= PTR_TO_USHORT(cur
->elem
);
270 TRACE("veth vlan tagged id: %u", vlan_tagged_id
);
274 case LXC_NET_MACVLAN
:
275 TRACE("type: macvlan");
277 if (netdev
->priv
.macvlan_attr
.mode
> 0) {
280 mode
= lxc_macvlan_flag_to_mode(
281 netdev
->priv
.macvlan_attr
.mode
);
282 TRACE("macvlan mode: %s",
283 mode
? mode
: "(invalid mode)");
287 TRACE("type: ipvlan");
290 mode
= lxc_ipvlan_flag_to_mode(netdev
->priv
.ipvlan_attr
.mode
);
291 TRACE("ipvlan mode: %s", mode
? mode
: "(invalid mode)");
294 isolation
= lxc_ipvlan_flag_to_isolation(netdev
->priv
.ipvlan_attr
.isolation
);
295 TRACE("ipvlan isolation: %s", isolation
? isolation
: "(invalid isolation)");
299 TRACE("vlan id: %d", netdev
->priv
.vlan_attr
.vid
);
304 if (netdev
->priv
.phys_attr
.ifindex
> 0)
305 TRACE("host side ifindex for phys device: %d",
306 netdev
->priv
.phys_attr
.ifindex
);
309 TRACE("type: empty");
315 ERROR("Invalid network type %d", netdev
->type
);
319 if (netdev
->type
!= LXC_NET_EMPTY
) {
321 netdev
->flags
== IFF_UP
? "up" : "none");
323 if (netdev
->link
[0] != '\0')
324 TRACE("link: %s", netdev
->link
);
326 /* l2proxy only used when link is specified */
327 if (netdev
->link
[0] != '\0')
328 TRACE("l2proxy: %s", netdev
->l2proxy
? "true" : "false");
330 if (netdev
->name
[0] != '\0')
331 TRACE("name: %s", netdev
->name
);
334 TRACE("hwaddr: %s", netdev
->hwaddr
);
337 TRACE("mtu: %s", netdev
->mtu
);
339 if (netdev
->upscript
)
340 TRACE("upscript: %s", netdev
->upscript
);
342 if (netdev
->downscript
)
343 TRACE("downscript: %s", netdev
->downscript
);
345 TRACE("ipv4 gateway auto: %s",
346 netdev
->ipv4_gateway_auto
? "true" : "false");
348 TRACE("ipv4 gateway dev: %s",
349 netdev
->ipv4_gateway_dev
? "true" : "false");
351 if (netdev
->ipv4_gateway
) {
352 inet_ntop(AF_INET
, netdev
->ipv4_gateway
,
353 bufinet4
, sizeof(bufinet4
));
354 TRACE("ipv4 gateway: %s", bufinet4
);
357 lxc_list_for_each_safe(cur
, &netdev
->ipv4
, next
) {
358 inet4dev
= cur
->elem
;
359 inet_ntop(AF_INET
, &inet4dev
->addr
, bufinet4
,
361 TRACE("ipv4 addr: %s", bufinet4
);
364 TRACE("ipv6 gateway auto: %s",
365 netdev
->ipv6_gateway_auto
? "true" : "false");
367 TRACE("ipv6 gateway dev: %s",
368 netdev
->ipv6_gateway_dev
? "true" : "false");
370 if (netdev
->ipv6_gateway
) {
371 inet_ntop(AF_INET6
, netdev
->ipv6_gateway
,
372 bufinet6
, sizeof(bufinet6
));
373 TRACE("ipv6 gateway: %s", bufinet6
);
376 lxc_list_for_each_safe(cur
, &netdev
->ipv6
, next
) {
377 inet6dev
= cur
->elem
;
378 inet_ntop(AF_INET6
, &inet6dev
->addr
, bufinet6
,
380 TRACE("ipv6 addr: %s", bufinet6
);
383 if (netdev
->type
== LXC_NET_VETH
) {
384 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv4_routes
, next
) {
385 inet4dev
= cur
->elem
;
386 if (!inet_ntop(AF_INET
, &inet4dev
->addr
, bufinet4
, sizeof(bufinet4
))) {
387 ERROR("Invalid ipv4 veth route");
391 TRACE("ipv4 veth route: %s/%u", bufinet4
, inet4dev
->prefix
);
394 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv6_routes
, next
) {
395 inet6dev
= cur
->elem
;
396 if (!inet_ntop(AF_INET6
, &inet6dev
->addr
, bufinet6
, sizeof(bufinet6
))) {
397 ERROR("Invalid ipv6 veth route");
401 TRACE("ipv6 veth route: %s/%u", bufinet6
, inet6dev
->prefix
);
408 static void lxc_free_netdev(struct lxc_netdev
*netdev
)
410 struct lxc_list
*cur
, *next
;
415 free(netdev
->upscript
);
416 free(netdev
->downscript
);
417 free(netdev
->hwaddr
);
420 free(netdev
->ipv4_gateway
);
421 lxc_list_for_each_safe(cur
, &netdev
->ipv4
, next
) {
427 free(netdev
->ipv6_gateway
);
428 lxc_list_for_each_safe(cur
, &netdev
->ipv6
, next
) {
434 if (netdev
->type
== LXC_NET_VETH
) {
435 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv4_routes
, next
) {
441 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv6_routes
, next
) {
447 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.vlan_tagged_ids
, next
) {
456 define_cleanup_function(struct lxc_netdev
*, lxc_free_netdev
);
458 bool lxc_remove_nic_by_idx(struct lxc_conf
*conf
, unsigned int idx
)
460 call_cleaner(lxc_free_netdev
) struct lxc_netdev
*netdev
= NULL
;
461 struct lxc_list
*cur
, *next
;
463 lxc_list_for_each_safe(cur
, &conf
->network
, next
) {
465 if (netdev
->idx
!= idx
)
476 void lxc_free_networks(struct lxc_list
*networks
)
478 struct lxc_list
*cur
, *next
;
480 lxc_list_for_each_safe (cur
, networks
, next
) {
481 struct lxc_netdev
*netdev
= cur
->elem
;
483 lxc_free_netdev(netdev
);
487 /* prevent segfaults */
488 lxc_list_init(networks
);
491 static struct lxc_veth_mode
{
495 { "bridge", VETH_MODE_BRIDGE
},
496 { "router", VETH_MODE_ROUTER
},
499 int lxc_veth_mode_to_flag(int *mode
, const char *value
)
501 for (size_t i
= 0; i
< sizeof(veth_mode
) / sizeof(veth_mode
[0]); i
++) {
502 if (strcmp(veth_mode
[i
].name
, value
) != 0)
505 *mode
= veth_mode
[i
].mode
;
509 return ret_errno(EINVAL
);
512 char *lxc_veth_flag_to_mode(int mode
)
514 for (size_t i
= 0; i
< sizeof(veth_mode
) / sizeof(veth_mode
[0]); i
++) {
515 if (veth_mode
[i
].mode
!= mode
)
518 return veth_mode
[i
].name
;
521 return ret_set_errno(NULL
, EINVAL
);
524 static struct lxc_macvlan_mode
{
528 { "private", MACVLAN_MODE_PRIVATE
},
529 { "vepa", MACVLAN_MODE_VEPA
},
530 { "bridge", MACVLAN_MODE_BRIDGE
},
531 { "passthru", MACVLAN_MODE_PASSTHRU
},
534 int lxc_macvlan_mode_to_flag(int *mode
, const char *value
)
536 for (size_t i
= 0; i
< sizeof(macvlan_mode
) / sizeof(macvlan_mode
[0]); i
++) {
537 if (strcmp(macvlan_mode
[i
].name
, value
))
540 *mode
= macvlan_mode
[i
].mode
;
544 return ret_errno(EINVAL
);
547 char *lxc_macvlan_flag_to_mode(int mode
)
549 for (size_t i
= 0; i
< sizeof(macvlan_mode
) / sizeof(macvlan_mode
[0]); i
++) {
550 if (macvlan_mode
[i
].mode
!= mode
)
553 return macvlan_mode
[i
].name
;
556 return ret_set_errno(NULL
, EINVAL
);
559 static struct lxc_ipvlan_mode
{
563 { "l3", IPVLAN_MODE_L3
},
564 { "l3s", IPVLAN_MODE_L3S
},
565 { "l2", IPVLAN_MODE_L2
},
568 int lxc_ipvlan_mode_to_flag(int *mode
, const char *value
)
570 for (size_t i
= 0; i
< sizeof(ipvlan_mode
) / sizeof(ipvlan_mode
[0]); i
++) {
571 if (strcmp(ipvlan_mode
[i
].name
, value
) != 0)
574 *mode
= ipvlan_mode
[i
].mode
;
578 return ret_errno(EINVAL
);
581 char *lxc_ipvlan_flag_to_mode(int mode
)
583 for (size_t i
= 0; i
< sizeof(ipvlan_mode
) / sizeof(ipvlan_mode
[0]); i
++) {
584 if (ipvlan_mode
[i
].mode
!= mode
)
587 return ipvlan_mode
[i
].name
;
590 return ret_set_errno(NULL
, EINVAL
);
593 static struct lxc_ipvlan_isolation
{
596 } ipvlan_isolation
[] = {
597 { "bridge", IPVLAN_ISOLATION_BRIDGE
},
598 { "private", IPVLAN_ISOLATION_PRIVATE
},
599 { "vepa", IPVLAN_ISOLATION_VEPA
},
602 int lxc_ipvlan_isolation_to_flag(int *flag
, const char *value
)
604 for (size_t i
= 0; i
< sizeof(ipvlan_isolation
) / sizeof(ipvlan_isolation
[0]); i
++) {
605 if (strcmp(ipvlan_isolation
[i
].name
, value
) != 0)
608 *flag
= ipvlan_isolation
[i
].flag
;
612 return ret_errno(EINVAL
);
615 char *lxc_ipvlan_flag_to_isolation(int flag
)
617 for (size_t i
= 0; i
< sizeof(ipvlan_isolation
) / sizeof(ipvlan_isolation
[0]); i
++) {
618 if (ipvlan_isolation
[i
].flag
!= flag
)
621 return ipvlan_isolation
[i
].name
;
624 return ret_set_errno(NULL
, EINVAL
);
627 int set_config_string_item(char **conf_item
, const char *value
)
631 if (lxc_config_value_empty(value
)) {
632 free_disarm(*conf_item
);
636 new_value
= strdup(value
);
638 return log_error_errno(-ENOMEM
, ENOMEM
, "Failed to duplicate string \"%s\"", value
);
640 free_move_ptr(*conf_item
, new_value
);
644 int set_config_string_item_max(char **conf_item
, const char *value
, size_t max
)
646 if (strlen(value
) >= max
)
647 return log_error_errno(-ENAMETOOLONG
, ENAMETOOLONG
, "%s is too long (>= %lu)", value
, (unsigned long)max
);
649 return set_config_string_item(conf_item
, value
);
652 int set_config_path_item(char **conf_item
, const char *value
)
654 return set_config_string_item_max(conf_item
, value
, PATH_MAX
);
657 int set_config_bool_item(bool *conf_item
, const char *value
, bool empty_conf_action
)
660 unsigned int val
= 0;
662 if (lxc_config_value_empty(value
)) {
663 *conf_item
= empty_conf_action
;
667 ret
= lxc_safe_uint(value
, &val
);
680 return ret_errno(EINVAL
);
683 int config_ip_prefix(struct in_addr
*addr
)
685 if (IN_CLASSA(addr
->s_addr
))
686 return 32 - IN_CLASSA_NSHIFT
;
688 if (IN_CLASSB(addr
->s_addr
))
689 return 32 - IN_CLASSB_NSHIFT
;
691 if (IN_CLASSC(addr
->s_addr
))
692 return 32 - IN_CLASSC_NSHIFT
;
697 int network_ifname(char *valuep
, const char *value
, size_t size
)
701 if (!valuep
|| !value
)
702 return ret_errno(EINVAL
);
704 retlen
= strlcpy(valuep
, value
, size
);
706 ERROR("Network device name \"%s\" is too long (>= %zu)", value
, size
);
711 bool lxc_config_net_is_hwaddr(const char *line
)
716 if (strncmp(line
, "lxc.net", 7) != 0)
719 if (strncmp(line
, "lxc.net.hwaddr", 14) == 0)
722 if (strncmp(line
, "lxc.network.hwaddr", 18) == 0)
725 if (sscanf(line
, "lxc.net.%u.%6s", &index
, tmp
) == 2 ||
726 sscanf(line
, "lxc.network.%u.%6s", &index
, tmp
) == 2)
727 return strncmp(tmp
, "hwaddr", 6) == 0;
732 void rand_complete_hwaddr(char *hwaddr
)
734 const char hex
[] = "0123456789abcdef";
739 seed
= randseed(false);
742 (void)randseed(true);
745 while (*curs
!= '\0' && *curs
!= '\n') {
746 if (*curs
== 'x' || *curs
== 'X') {
747 if (curs
- hwaddr
== 1) {
748 /* ensure address is unicast */
750 *curs
= hex
[rand_r(&seed
) & 0x0E];
752 *curs
= hex
[rand_r(&seed
) & 0x0F];
754 *curs
= hex
[rand() & 0x0E];
756 *curs
= hex
[rand() & 0x0F];
764 bool new_hwaddr(char *hwaddr
)
770 seed
= randseed(false);
772 ret
= snprintf(hwaddr
, 18, "00:16:3e:%02x:%02x:%02x", rand_r(&seed
) % 255,
773 rand_r(&seed
) % 255, rand_r(&seed
) % 255);
776 (void)randseed(true);
778 ret
= snprintf(hwaddr
, 18, "00:16:3e:%02x:%02x:%02x", rand() % 255,
779 rand() % 255, rand() % 255);
781 if (ret
< 0 || ret
>= 18) {
782 return log_error_errno(false, EIO
, "Failed to call snprintf()");
788 int lxc_get_conf_str(char *retv
, int inlen
, const char *value
)
795 value_len
= strlen(value
);
796 if (retv
&& inlen
>= value_len
+ 1)
797 memcpy(retv
, value
, value_len
+ 1);
802 int lxc_get_conf_bool(struct lxc_conf
*c
, char *retv
, int inlen
, bool v
)
810 memset(retv
, 0, inlen
);
812 strprint(retv
, inlen
, "%d", v
);
817 int lxc_get_conf_int(struct lxc_conf
*c
, char *retv
, int inlen
, int v
)
825 memset(retv
, 0, inlen
);
827 strprint(retv
, inlen
, "%d", v
);
832 int lxc_get_conf_size_t(struct lxc_conf
*c
, char *retv
, int inlen
, size_t v
)
840 memset(retv
, 0, inlen
);
842 strprint(retv
, inlen
, "%zu", v
);
847 int lxc_get_conf_uint64(struct lxc_conf
*c
, char *retv
, int inlen
, uint64_t v
)
855 memset(retv
, 0, inlen
);
857 strprint(retv
, inlen
, "%"PRIu64
, v
);
862 static int lxc_container_name_to_pid(const char *lxcname_or_pid
,
869 pid
= strtol(lxcname_or_pid
, &err
, 10);
870 if (*err
!= '\0' || pid
< 1) {
871 __put_lxc_container
struct lxc_container
*c
= NULL
;
873 c
= lxc_container_new(lxcname_or_pid
, lxcpath
);
875 return log_error_errno(-EINVAL
, EINVAL
, "\"%s\" is not a valid pid nor a container name", lxcname_or_pid
);
877 if (!c
->may_control(c
))
878 return log_error_errno(-EPERM
, EPERM
, "Insufficient privileges to control container \"%s\"", c
->name
);
880 pid
= c
->init_pid(c
);
882 return log_error_errno(-EINVAL
, EINVAL
, "Container \"%s\" is not running", c
->name
);
888 return log_error_errno(-errno
, errno
, "Failed to send signal to pid %d", (int)pid
);
893 int lxc_inherit_namespace(const char *nsfd_path
, const char *lxcpath
,
894 const char *namespace)
896 __do_free
char *dup
= NULL
;
900 if (nsfd_path
[0] == '/') {
901 return open(nsfd_path
, O_RDONLY
| O_CLOEXEC
);
904 lastslash
= strrchr(nsfd_path
, '/');
906 dup
= strdup(nsfd_path
);
908 return ret_errno(ENOMEM
);
910 dup
[lastslash
- nsfd_path
] = '\0';
911 lxcpath
= lastslash
+ 1;
912 nsfd_path
= lastslash
+ 1;
915 pid
= lxc_container_name_to_pid(nsfd_path
, lxcpath
);
919 fd
= lxc_preserve_ns(pid
, namespace);
931 static const struct signame signames
[] = {
964 { SIGSTKFLT
, "STKFLT" },
979 { SIGVTALRM
, "VTALRM" },
985 { SIGWINCH
, "WINCH" },
1003 { SIGUNUSED
, "UNUSED" },
1010 static int sig_num(const char *sig
)
1013 unsigned int signum
;
1015 ret
= lxc_safe_uint(sig
, &signum
);
1022 static int rt_sig_num(const char *signame
)
1024 int rtmax
= 0, sig_n
= 0;
1026 if (strncasecmp(signame
, "max-", 4) == 0)
1030 if (!isdigit(*signame
))
1031 return ret_errno(EINVAL
);
1033 sig_n
= sig_num(signame
);
1034 sig_n
= rtmax
? SIGRTMAX
- sig_n
: SIGRTMIN
+ sig_n
;
1035 if (sig_n
> SIGRTMAX
|| sig_n
< SIGRTMIN
)
1036 return ret_errno(EINVAL
);
1041 int sig_parse(const char *signame
)
1045 if (isdigit(*signame
)) {
1046 return sig_num(signame
);
1047 } else if (strncasecmp(signame
, "sig", 3) == 0) {
1049 if (strncasecmp(signame
, "rt", 2) == 0)
1050 return rt_sig_num(signame
+ 2);
1052 for (n
= 0; n
< sizeof(signames
) / sizeof((signames
)[0]); n
++)
1053 if (strcasecmp(signames
[n
].name
, signame
) == 0)
1054 return signames
[n
].num
;
1057 return ret_errno(EINVAL
);