Date:2011-05-18 18:34:26 (12 years 10 months ago)
Author:Werner Almesberger
Commit:43f179d6d8482f15958248cb45c1fc437bab6ee4
Message:tools/lib/: new helper function for daemonification

- include/daemon.h (daemonize), lib/daemon.c: shed all ties with the
process' previous surroundings
- lib/Makefile (OBJS): added daemon.o
Files: prod/doc/index.html (4 diffs)
tools/include/daemon.h (1 diff)
tools/lib/Makefile (1 diff)
tools/lib/daemon.c (1 diff)

Change Details

prod/doc/index.html
2929Defective devices can be discarded or retained for a deeper analysis.
3030
3131
32<!-- ====================================================================== -->
33
34
3235<H2>Terminology</H2>
3336
3437<DL>
...... 
7376</DL>
7477
7578
76<H2>Setup</H2>
79<!-- ====================================================================== -->
80
81
82<H2>Software setup</H2>
83
84Before performing any production tests, various pieces of software
85need to be installed on Ben and PC, and configuration settings
86@@@
87
88
89<!-- ---------------------------------------------------------------------- -->
90
7791
7892<H3>PC software installation</H3>
79<H3>Ben software installation</H3>
93
94@@@
95
96<H4>Install ben-wpan tools</H4>
97
98@@@
99
100<H4>Register Ben host name</H4>
101
102To simplify accessing the Ben via TCP/IP, its IP address should be
103registered in the hosts file on the PC. If the Ben is running OpenWrt,
104use the following command:
105<PRE>
106echo 192.168.254.101 ben >>/etc/hosts
107</PRE>
108<P>
109If the Ben is running Jlime, the address would be as follows:
110<PRE>
111echo 192.168.1.202 ben >>/etc/hosts
112</PRE>
113<P>
114If using the same PC with Bens running OpenWrt and Jlime, one may choose
115different host names depending on the distribution, and adapt the commands
116used in the production and testing process accordingly. For example,
117<PRE>
118echo 192.168.254.101 ben >>/etc/hosts
119echo 192.168.1.202 jlime >>/etc/hosts
120</PRE>
121
122
123<!-- ---------------------------------------------------------------------- -->
124
125
80126<H3>Ben software setup</H3>
127
128This needs to be done each time the Ben is booted.
129
130<H4>Enable network access</H4>
131<H4>Silence other 8:10 card users</H4>
132
133
134<!-- ---------------------------------------------------------------------- -->
135
136
137<H3>Ben software installation</H3>
138
139<H4>Password-less remote access</H4>
140
141To enable password-less remote access from the PC, setup to betwork
142access to the Ben and run the following command:
143<PRE>
144ssh ben 'cat >>/etc/dropbear/authorized_keys' <~/.ssh/id_rsa.pub
145</PRE>
146
147
148<!-- ---------------------------------------------------------------------- -->
149
150
81151<H3>Test profiles</H3>
82152
83153
154<!-- ====================================================================== -->
155
156
84157<H2>Flashing (atusb only)<H2>
85158
159<!-- ---------------------------------------------------------------------- -->
160
161
86162<H3>Flashing the boot loader</H3>
87163
88164<P>
...... 
90166<P>
91167
92168
169<!-- ---------------------------------------------------------------------- -->
170
171
93172<H3>Flashing the application</H3>
94173
95174<P>
...... 
97176<P>
98177
99178
179<!-- ====================================================================== -->
180
181
100182<H2>Functional test</H2>
101183
184<!-- ---------------------------------------------------------------------- -->
185
186
102187<H3>Test setup for atben</H3>
103188
104189<P>
105190<IMG src="setup-A.png">
106191<P>
107192
193<!-- ---------------------------------------------------------------------- -->
194
195
108196<H3>Test setup for atusb</H3>
109197
110198<P>
111199<IMG src="setup-B.png">
112200<P>
113201
202<!-- ---------------------------------------------------------------------- -->
203
204
114205<H3>Test procedure</H3>
115206
207
208<!-- ====================================================================== -->
209
210
116211<H2>Fault analysis</H2>
117212
213<!-- ---------------------------------------------------------------------- -->
214
215
118216<H3>Component placement and orientation</H3>
119217
218<!-- ---------------------------------------------------------------------- -->
219
220
120221<H3>Supply voltages</H3>
121222
223<!-- ---------------------------------------------------------------------- -->
224
225
122226<H3>Clock frequency</H3>
123227
124228The flawless performance of the crystal oscillator is crucial for
tools/include/daemon.h
1/*
2 * include/daemon.h - Helper functions for proper daemonification
3 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#ifndef DAEMON_H
15#define DAEMON_H
16
17#include <unistd.h>
18
19
20pid_t daemonize(void);
21
22#endif /* !DAEMON_H */
tools/lib/Makefile
1919OBJS_ben_jlime = atben.o
2020OBJS_ben_openwrt = atben.o
2121
22OBJS = atrf.o atnet.o misctxrx.o cwtest.o netio.o $(OBJS_$(TARGET))
22OBJS = atrf.o atnet.o misctxrx.o cwtest.o netio.o daemon.o $(OBJS_$(TARGET))
2323
2424.PHONY: all clean spotless
2525
tools/lib/daemon.c
1/*
2 * lib/daemon.c - Helper functions for proper daemonification
3 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <unistd.h>
17
18#include "daemon.h"
19
20
21pid_t daemonize(void)
22{
23    pid_t pid;
24    int i;
25
26    pid = fork();
27    if (pid < 0) {
28        perror("fork");
29        exit(1);
30    }
31    if (pid)
32        return pid;
33    if (setsid() < 0) {
34        perror("setsid");
35        exit(1);
36    }
37    for (i = 0; i <= 2; i++)
38        (void) close(i);
39    (void) chdir("/");
40    return 0;
41}

Archive Download the corresponding diff file



interactive