...
 
Commits (9)
......@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
return -1;
}
strncpy(ifr.ifr_name, rxdev, IFNAMSIZ);
namecpy(ifr.ifr_name, rxdev);
printf("RX rxsock=%d, ifr_name=%s\n", rxsock, ifr.ifr_name);
if (ioctl(rxsock, SIOCGIFINDEX, &ifr) < 0) {
......@@ -282,7 +282,7 @@ int main(int argc, char *argv[])
goto failure1;
}
strncpy(ifr.ifr_name, txdev, IFNAMSIZ);
namecpy(ifr.ifr_name, txdev);
printf("TX txsock=%d, ifr_name=%s\n", txsock, ifr.ifr_name);
if (ioctl(txsock, SIOCGIFINDEX, &ifr) < 0) {
......
......@@ -40,6 +40,7 @@
#include <net/if.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <boilerplate/ancillaries.h>
char buffer[10*1024];
int sock;
......@@ -72,7 +73,7 @@ int main(int argc, char *argv[])
if (argc > 1) {
struct ifreq ifr;
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
namecpy(ifr.ifr_name, argv[1]);
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) {
perror("cannot get interface index");
close(sock);
......
......@@ -1353,7 +1353,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
case 'F':
case OPT_FIFO:
use_fifo = 1;
strncpy(fifopath, optarg, strlen(optarg));
strncpy(fifopath, optarg, sizeof(fifopath) - 1);
break;
case 'H':
......@@ -1458,7 +1458,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
case 'T':
case OPT_TRACER:
tracetype = CUSTOM;
strncpy(tracer, optarg, sizeof(tracer));
strncpy(tracer, optarg, sizeof(tracer) - 1);
break;
case 'u':
case OPT_UNBUFFERED:
......
......@@ -34,7 +34,7 @@ void __namecpy_requires_character_array_as_destination(void);
({ \
if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
__namecpy_requires_character_array_as_destination(); \
strncpy((__dst), __src, sizeof(__dst) - 1); \
strncpy((__dst), __src, sizeof(__dst)); \
__dst[sizeof(__dst) - 1] = '\0'; \
__dst; \
})
......
......@@ -58,7 +58,7 @@ void __knamecpy_requires_character_array_as_destination(void);
({ \
if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
__knamecpy_requires_character_array_as_destination(); \
strncpy((__dst), __src, sizeof(__dst) - 1); \
strncpy((__dst), __src, sizeof(__dst)); \
__dst[sizeof(__dst) - 1] = '\0'; \
__dst; \
})
......
......@@ -140,6 +140,33 @@ struct xnsched_class {
const union xnsched_policy_param *p);
void (*sched_migrate)(struct xnthread *thread,
struct xnsched *sched);
int (*sched_chkparam)(struct xnthread *thread,
const union xnsched_policy_param *p);
/**
* Set base scheduling parameters. This routine is indirectly
* called upon a change of base scheduling settings through
* __xnthread_set_schedparam() -> xnsched_set_policy(),
* exclusively.
*
* The scheduling class implementation should do the necessary
* housekeeping to comply with the new settings.
* thread->base_class is up to date before the call is made,
* and should be considered for the new weighted priority
* calculation. On the contrary, thread->sched_class should
* NOT be referred to by this handler.
*
* sched_setparam() is NEVER involved in PI or PP
* management. However it must deny a priority update if it
* contradicts an ongoing boost for @a thread. This is
* typically what the xnsched_set_effective_priority() helper
* does for such handler.
*
* @param thread Affected thread.
* @param p New base policy settings.
*
* @return True if the effective priority was updated
* (thread->cprio).
*/
void (*sched_setparam)(struct xnthread *thread,
const union xnsched_policy_param *p);
void (*sched_getparam)(struct xnthread *thread,
......@@ -494,6 +521,16 @@ static inline void xnsched_tick(struct xnsched *sched)
sched_class->sched_tick(sched);
}
static inline int xnsched_chkparam(struct xnsched_class *sched_class,
struct xnthread *thread,
const union xnsched_policy_param *p)
{
if (sched_class->sched_chkparam)
return sched_class->sched_chkparam(thread, p);
return 0;
}
static inline int xnsched_declare(struct xnsched_class *sched_class,
struct xnthread *thread,
const union xnsched_policy_param *p)
......
......@@ -282,8 +282,8 @@ static void xnsched_quota_trackprio(struct xnthread *thread,
thread->cprio = thread->bprio;
}
static int xnsched_quota_declare(struct xnthread *thread,
const union xnsched_policy_param *p)
static int xnsched_quota_chkparam(struct xnthread *thread,
const union xnsched_policy_param *p)
{
struct xnsched_quota_group *tg;
struct xnsched_quota *qs;
......@@ -778,10 +778,10 @@ struct xnsched_class xnsched_class_quota = {
.sched_tick = NULL,
.sched_rotate = NULL,
.sched_migrate = xnsched_quota_migrate,
.sched_chkparam = xnsched_quota_chkparam,
.sched_setparam = xnsched_quota_setparam,
.sched_getparam = xnsched_quota_getparam,
.sched_trackprio = xnsched_quota_trackprio,
.sched_declare = xnsched_quota_declare,
.sched_forget = xnsched_quota_forget,
.sched_kick = xnsched_quota_kick,
#ifdef CONFIG_XENO_OPT_VFILE
......
......@@ -284,11 +284,9 @@ static void xnsched_sporadic_trackprio(struct xnthread *thread,
thread->cprio = thread->bprio;
}
static int xnsched_sporadic_declare(struct xnthread *thread,
const union xnsched_policy_param *p)
static int xnsched_sporadic_chkparam(struct xnthread *thread,
const union xnsched_policy_param *p)
{
struct xnsched_sporadic_data *pss;
if (p->pss.low_prio != -1 &&
(p->pss.low_prio < XNSCHED_SPORADIC_MIN_PRIO ||
p->pss.low_prio > XNSCHED_SPORADIC_MAX_PRIO))
......@@ -313,6 +311,14 @@ static int xnsched_sporadic_declare(struct xnthread *thread,
if (p->pss.max_repl < 1 || p->pss.max_repl > MAX_REPLENISH)
return -EINVAL;
return 0;
}
static int xnsched_sporadic_declare(struct xnthread *thread,
const union xnsched_policy_param *p)
{
struct xnsched_sporadic_data *pss;
pss = xnmalloc(sizeof(*pss));
if (pss == NULL)
return -ENOMEM;
......@@ -529,6 +535,7 @@ struct xnsched_class xnsched_class_sporadic = {
.sched_tick = NULL,
.sched_rotate = NULL,
.sched_migrate = NULL,
.sched_chkparam = xnsched_sporadic_chkparam,
.sched_setparam = xnsched_sporadic_setparam,
.sched_getparam = xnsched_sporadic_getparam,
.sched_trackprio = xnsched_sporadic_trackprio,
......
......@@ -154,17 +154,24 @@ static void xnsched_tp_trackprio(struct xnthread *thread,
thread->cprio = thread->bprio;
}
static int xnsched_tp_declare(struct xnthread *thread,
const union xnsched_policy_param *p)
static int xnsched_tp_chkparam(struct xnthread *thread,
const union xnsched_policy_param *p)
{
struct xnsched *sched = thread->sched;
struct xnsched_tp *tp = &sched->tp;
struct xnsched_tp *tp = &thread->sched->tp;
if (tp->gps == NULL ||
p->tp.prio < XNSCHED_TP_MIN_PRIO ||
p->tp.prio > XNSCHED_TP_MAX_PRIO)
return -EINVAL;
return 0;
}
static int xnsched_tp_declare(struct xnthread *thread,
const union xnsched_policy_param *p)
{
struct xnsched *sched = thread->sched;
list_add_tail(&thread->tp_link, &sched->tp.threads);
return 0;
......@@ -425,6 +432,7 @@ struct xnsched_class xnsched_class_tp = {
.sched_tick = NULL,
.sched_rotate = NULL,
.sched_migrate = xnsched_tp_migrate,
.sched_chkparam = xnsched_tp_chkparam,
.sched_setparam = xnsched_tp_setparam,
.sched_getparam = xnsched_tp_getparam,
.sched_trackprio = xnsched_tp_trackprio,
......
......@@ -67,8 +67,8 @@ void xnsched_weak_trackprio(struct xnthread *thread,
thread->cprio = thread->bprio;
}
static int xnsched_weak_declare(struct xnthread *thread,
const union xnsched_policy_param *p)
static int xnsched_weak_chkparam(struct xnthread *thread,
const union xnsched_policy_param *p)
{
if (p->weak.prio < XNSCHED_WEAK_MIN_PRIO ||
p->weak.prio > XNSCHED_WEAK_MAX_PRIO)
......@@ -199,7 +199,7 @@ struct xnsched_class xnsched_class_weak = {
.sched_rotate = NULL,
.sched_forget = NULL,
.sched_kick = NULL,
.sched_declare = xnsched_weak_declare,
.sched_chkparam = xnsched_weak_chkparam,
.sched_setparam = xnsched_weak_setparam,
.sched_trackprio = xnsched_weak_trackprio,
.sched_getparam = xnsched_weak_getparam,
......
......@@ -380,6 +380,10 @@ int xnsched_set_policy(struct xnthread *thread,
{
int ret;
ret = xnsched_chkparam(sched_class, thread, p);
if (ret)
return ret;
/*
* Declaring a thread to a new scheduling class may fail, so
* we do that early, while the thread is still a member of the
......
......@@ -31,6 +31,7 @@
#include <errno.h>
#include <getopt.h>
#include <sys/mman.h>
#include <boilerplate/ancillaries.h>
#include <rtdm/can.h>
......@@ -81,7 +82,7 @@ static int string_to_ctrlmode(char *str)
int main(int argc, char *argv[])
{
char ifname[16];
char ifname[IFNAMSIZ];
int can_fd = -1;
int new_baudrate = -1;
int new_mode = -1;
......@@ -159,8 +160,8 @@ int main(int argc, char *argv[])
return 0;
}
strncpy(ifname, argv[optind], IFNAMSIZ);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
namecpy(ifname, argv[optind]);
namecpy(ifr.ifr_name, ifname);
if (optind == argc - 2) { /* Get mode setting */
new_mode = string_to_mode(argv[optind + 1]);
......
......@@ -7,6 +7,7 @@
#include <getopt.h>
#include <alchemy/task.h>
#include <boilerplate/ancillaries.h>
#include <rtdm/can.h>
......@@ -248,7 +249,7 @@ int main(int argc, char **argv)
if (verbose)
printf("interface %s\n", argv[optind]);
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
namecpy(ifr.ifr_name, argv[optind]);
if (verbose)
printf("s=%d, ifr_name=%s\n", s, ifr.ifr_name);
......
......@@ -6,6 +6,7 @@
#include <errno.h>
#include <getopt.h>
#include <boilerplate/ancillaries.h>
#include <alchemy/task.h>
#include <alchemy/timer.h>
......@@ -231,7 +232,7 @@ int main(int argc, char **argv)
printf("Using loopback=%d\n", loopback);
}
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
namecpy(ifr.ifr_name, argv[optind]);
if (verbose)
printf("s=%d, ifr_name=%s\n", s, ifr.ifr_name);
......