Commit f190e8b5 authored by claes's avatar claes

New strategi to set prio, start as root, set prio and set uid to pwrp

parent 7776129a
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
# include <string.h> # include <string.h>
#endif #endif
#if defined(OS_LINUX)
# include <pwd.h>
#endif
#include "pwr.h" #include "pwr.h"
#include "pwr_class.h" #include "pwr_class.h"
#include "pwr_baseclasses.h" #include "pwr_baseclasses.h"
...@@ -58,12 +62,32 @@ plc_thread ( ...@@ -58,12 +62,32 @@ plc_thread (
pwr_tStatus sts; pwr_tStatus sts;
int rel_vec; int rel_vec;
int phase; int phase;
uid_t ruid;
plc_sProcess *pp = tp->pp; plc_sProcess *pp = tp->pp;
/* Phase 1. */ /* Phase 1. */
tp->init(1, tp); tp->init(1, tp);
thread_SetPrio(&tp->tid, tp->prio);
/* Once thread's has set it's priority don't run as root */
#if defined(OS_LINUX)
struct passwd *pwd;
ruid = getuid();
if (ruid == 0) {
pwd = getpwnam("pwrp");
if (pwd != NULL) {
setreuid(pwd->pw_uid, pwd->pw_uid);
}
}
else
setreuid(ruid, ruid);
#endif
que_Put(&sts, &tp->q_out, &tp->event, (void *)1); que_Put(&sts, &tp->q_out, &tp->event, (void *)1);
phase = (int)que_Get(&sts, &tp->q_in, NULL, NULL); phase = (int)que_Get(&sts, &tp->q_in, NULL, NULL);
pwr_Assert(phase == 2); pwr_Assert(phase == 2);
...@@ -78,8 +102,6 @@ plc_thread ( ...@@ -78,8 +102,6 @@ plc_thread (
/* Phase 3. */ /* Phase 3. */
thread_SetPrio(&tp->tid, tp->prio);
rel_vec = ((tp->pp->PlcProcess->ChgCount - 1) % 2) + 1; rel_vec = ((tp->pp->PlcProcess->ChgCount - 1) % 2) + 1;
sts = io_init(io_mProcess_Plc, tp->aref.Objid, &tp->plc_io_ctx, rel_vec, tp->f_scan_time); sts = io_init(io_mProcess_Plc, tp->aref.Objid, &tp->plc_io_ctx, rel_vec, tp->f_scan_time);
if (EVEN(sts)) { if (EVEN(sts)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment