View | Details | Raw Unified
Collapse All | Expand All

(-)irda-utils-0.9.16/irattach/util.c.alt-irattach-daemonize (-1 / +15 lines)
 Lines 158-163   void fork_now(int ttyfd) Link Here 
158
{
158
{
159
	int ret;
159
	int ret;
160
	int i;
160
	int i;
161
	int fd;
161
162
162
	if ((ret = fork()) > 0)
163
	if ((ret = fork()) > 0)
163
		exit(0);
164
		exit(0);
 Lines 173-182   void fork_now(int ttyfd) Link Here 
173
	}
174
	}
174
175
175
	/* Close all open inherited files! Except for ttyfd! */
176
	/* Close all open inherited files! Except for ttyfd! */
176
	for (i = 0; i < 64; i++)
177
	for (i = 0; i < sysconf(_SC_OPEN_MAX); i++)
177
		if(i != ttyfd)
178
		if(i != ttyfd)
178
			close(i);
179
			close(i);
179
180
181
	/* Redirect standard descriptors to /dev/null to avoid trouble */
182
	fd = open("/dev/null", O_RDWR);
183
	if (fd >= 0) {
184
		if (fd != STDIN_FILENO)
185
			dup2(fd, STDIN_FILENO);
186
		if (fd != STDOUT_FILENO)
187
			dup2(fd, STDOUT_FILENO);
188
		if (fd != STDERR_FILENO)
189
			dup2(fd, STDERR_FILENO);
190
		if (fd > STDERR_FILENO)
191
			close(fd);
192
	}
193
180
	write_pid();
194
	write_pid();
181
} 
195
} 
182
196