Skip to content

Commit 60905c7

Browse files
author
Demo User
committed
move PID directory and fix package permissions of /var/lib/robotcontrol
1 parent 34f6fd2 commit 60905c7

File tree

5 files changed

+55
-63
lines changed

5 files changed

+55
-63
lines changed

debian/librobotcontrol.lintian-overrides

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ librobotcontrol: maintainer-script-calls-systemctl *
88
librobotcontrol: maintainer-script-ignores-errors *
99
librobotcontrol: binary-without-manpage *
1010
librobotcontrol: package-name-doesnt-match-sonames *
11+
librobotcontrol: non-standard-dir-perm var/lib/robotcontrol/ *

debian/rules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
#!/usr/bin/make -f
22
%:
33
dh $@
4+
5+
override_dh_fixperms:
6+
dh_fixperms \
7+
--exclude var/lib/robotcontrol \
8+
--exclude var/run/robotcontrol
9+

library/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ INCLUDEDIR := include
66
SONAME := librobotcontrol.so.1
77
FULLNAME := librobotcontrol.so.1.0.0
88
TARGET := $(LIBDIR)/$(FULLNAME)
9+
RC_VAR_DIR := var/lib/robotcontrol
910

1011
# file definitions for rules
1112
SOURCES := $(shell find $(SRCDIR) -type f -name *.c)
@@ -79,12 +80,12 @@ native:
7980

8081
install:
8182
$(MAKE)
82-
@$(INSTALLDIRWRITE) $(DESTDIR)/var/lib/robotcontrol
8383
@$(INSTALLDIR) $(DESTDIR)$(prefix)/include
8484
@cp -r include/* $(DESTDIR)$(prefix)/include
8585
@$(INSTALLDIR) $(DESTDIR)$(prefix)/lib
8686
@$(INSTALL) $(TARGET) $(DESTDIR)$(prefix)/lib
8787
@ln -sf $(FULLNAME) $(DESTDIR)$(prefix)/lib/$(SONAME)
88+
@$(INSTALLDIRWRITE) $(DESTDIR)/$(RC_VAR_DIR)
8889
@echo "Library Install Complete"
8990

9091
# cleanup local binaries

library/include/rc/start_stop.h

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
11
/**
22
* <rc/start_stop.h>
33
*
4-
* @brief cleanly start and stop a process, signal handling, program flow
5-
*
6-
* It can be tricky to manage the starting and stopping of mutiple threads and
7-
* loops. Since the robotics cape library has several background threads in
8-
* addition to any user-created threads, we encourage the use of the
9-
* consolidated high-level process control method described here. These
10-
* functions allow easy implementation of good-practice process handling
11-
* including a global shutdown flag, a signal handler, making & deleting a PID
12-
* file, stopping previously running copies of a program, and stopping a program
13-
* when it's in the background.
14-
*
15-
* The rc_state_t struct tries to cover the majority of use cases in the context
16-
* of a robotics application. The user should start their program main()
17-
* function by setting the state to UNINITIALIZED and enabling the signal
18-
* handler before doing hardware initialization and starting threads. When the
19-
* user's own initialization sequence is complete they should set the flow state
20-
* to PAUSED or RUNNING to indicate to the newly created threads that the
21-
* program should now behave in normal ongoing operational mode.
22-
*
23-
* During normal operation, the user may elect to implement a PAUSED state where
24-
* the user's threads may keep running to read sensors but do not actuate
25-
* motors, leaving their robot in a safe state. For example, pressing the pause
26-
* button could be assigned to change this state back and forth between RUNNING
27-
* and PAUSED. This is entirely optional.
28-
*
29-
* The most important state here is EXITING. The signal handler described here intercepts the SIGINT signal when the user presses
30-
* Ctrl-C and sets the state to EXITING. It is then up to the user's
31-
* threads to watch for this condition and exit cleanly. The user
32-
* may also set the state to EXITING at any time to trigger the closing of
33-
* their own threads and Robotics Cape library's own background threads.
34-
*
35-
* The flow state variable is kept in the robotics cape library's memory
36-
* space and should be read and modified by the rc_get_state() and
37-
* rc_set_state() functions above. The user may optionally use the
38-
* rc_print_state() function to print a human readable version of the state enum
39-
* to the screen.
4+
* @brief cleanly start and stop a process, signal handling, program flow
5+
*
6+
* It can be tricky to manage the starting and stopping of mutiple
7+
* threads and loops. Since the robot control library has several
8+
* background threads in addition to any user-created threads, we
9+
* encourage the use of the consolidated high-level process control
10+
* method described here. These functions allow easy implementation
11+
* of good-practice process handling including a global shutdown
12+
* flag, a signal handler, making & deleting a PID file, stopping
13+
* previously running copies of a program, and stopping a program
14+
* when it's in the background.
15+
*
16+
* The rc_state_t struct tries to cover the majority of use cases in
17+
* the context of a robotics application. The user should start
18+
* their program main() function by setting the state to
19+
* UNINITIALIZED and enabling the signal handler before doing
20+
* hardware initialization and starting threads. When the user's own
21+
* initialization sequence is complete they should set the flow
22+
* state to PAUSED or RUNNING to indicate to the newly created
23+
* threads that the program should now behave in normal ongoing
24+
* operational mode.
25+
*
26+
* During normal operation, the user may elect to implement a PAUSED
27+
* state where the user's threads may keep running to read sensors
28+
* but do not actuate motors, leaving their robot in a safe state.
29+
* For example, pressing the pause button could be assigned to
30+
* change this state back and forth between RUNNING and PAUSED. This
31+
* is entirely optional.
32+
*
33+
* The most important state here is EXITING. The signal handler
34+
* described here intercepts the SIGINT signal when the user presses
35+
* Ctrl-C and sets the state to EXITING. It is then up to the user's
36+
* threads to watch for this condition and exit cleanly. The user
37+
* may also set the state to EXITING at any time to trigger the
38+
* closing of their own threads and robot control library's own
39+
* background threads.
40+
*
41+
* The flow state variable is kept in the robot control library's
42+
* memory space and should be read and modified by the
43+
* rc_get_state() and rc_set_state() functions above. The user may
44+
* optionally use the rc_print_state() function to print a human
45+
* readable version of the state enum to the screen.
4046
*
4147
*
4248
* @addtogroup start_stop
@@ -50,8 +56,8 @@
5056
extern "C" {
5157
#endif
5258

53-
#define RC_PID_DIR "/var/run/roboticscape"
54-
#define RC_PID_FILE "/var/run/roboticscape/roboticscape.pid"
59+
#define RC_PID_DIR "/run/shm/"
60+
#define RC_PID_FILE "/run/shm/robotcontrol.pid"
5561

5662
/**
5763
* @brief process state variable, read and modify by rc_get_state,
@@ -91,7 +97,7 @@ void rc_set_state(rc_state_t new_state);
9197
int rc_print_state();
9298

9399
/**
94-
* @brief Makes a PID file RC_PID_FILE (/var/run/robotics_cape.pid)
100+
* @brief Makes a PID file RC_PID_FILE (/run/shm/robotcontrol.pid)
95101
* containing the current PID of your process
96102
*
97103
* @return Returns 0 if successful. If that file already exists then it is

library/src/start_stop.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ int rc_make_pid_file()
6565
{
6666
FILE *fd;
6767
DIR* dir;
68-
int ret;
6968
pid_t current_pid;
7069

7170
// start by checking if a pid file exists
@@ -79,30 +78,9 @@ int rc_make_pid_file()
7978
errno=0;
8079
dir = opendir(RC_PID_DIR);
8180
if(dir) closedir(dir); // exists, yay!
82-
else if(errno==ENOENT){
83-
// make missing directory
84-
// try giving 777 permissions but umask will overwrite it
85-
ret = mkdir(RC_PID_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
86-
if(ret==-1 && errno==EACCES){
87-
fprintf(stderr,"ERROR in rc_make_pid_file, need to be root to create %s\n",RC_PID_DIR);
88-
fprintf(stderr,"This should have been done by the roboticscape systemd service\n");
89-
fprintf(stderr,"Make sure the service is running by executing:\n");
90-
fprintf(stderr,"sudo systemctl enable roboticscape && sudo systemctl restart roboticscape\n");
91-
return -1;
92-
}
93-
if(ret==-1){
94-
perror("ERROR in rc_make_pid_file trying to make directory /var/run/roboticscape");
95-
return -1;
96-
}
97-
// now give proper permissions
98-
if(chmod(RC_PID_DIR, S_IRWXU | S_IRWXG | S_IRWXO)==-1){
99-
perror("ERROR in rc_make_pid_file setting permissions for /var/run/roboticscape");
100-
return -1;
101-
}
102-
}
10381
else{
10482
//opendir() failed for some other reason.
105-
perror("ERROR in rc_make_pid_file trying to open /var/run/roboticscape");
83+
perror("ERROR in rc_make_pid_file trying to open /run/shm/");
10684
return -1;
10785
}
10886

0 commit comments

Comments
 (0)