Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b80302

Browse files
committed
start implement ssu_crond
1 parent 01194ef commit 9b80302

File tree

6 files changed

+94
-14
lines changed

6 files changed

+94
-14
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Execute files
22
ssu_crontab
3+
ssu_crond
34
ssu_rsync
45

56
# Temporary files

‎Makefile‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ CFLAGS = -c -W -Wall -Wextra -O2 -g $(INC)
1313

1414
# Execute program file
1515
CRONTAB = ssu_crontab
16+
CROND = ssu_crond
1617
RSYNC = ssu_rsync
1718
# Source file
1819
CRONTAB_SRCS = ssu_crontab.c
20+
CROND_SRCS = ssu_crond.c
1921
RSYNC_SRCS = ssu_rsync.c
2022
SRCS = $(CRONTAB_SRCS) $(CROND_SRCS) $(RSYNC_SRCS)
2123
# Object file
2224
CRONTAB_OBJS = $(CRONTAB_SRCS:.c=.o)
25+
CROND_OBJS = $(CROND_SRCS:.c=.o)
2326
RSYNC_OBJS = $(RSYNC_SRCS:.c=.o)
2427
OBJS = $(CRONTAB_OBJS) $(CROND_OBJS) $(RSYNC_OBJS)
2528
# Header file
@@ -35,9 +38,12 @@ INC =
3538
# make all: Make all execute file
3639
all : $(OBJS)
3740
$(CC) -o $(CRONTAB) $(CRONTAB_OBJS) $(LIBS)
41+
$(CC) -o $(CROND) $(CROND_OBJS) $(LIBS)
3842
$(CC) -o $(RSYNC) $(RSYNC_OBJS) $(LIBS)
3943
$(CRONTAB) : $(CRONTAB_OBJS)
4044
$(CC) -o $@ $^ $(LIBS)
45+
$(CROND) : $(CROND_OBJS)
46+
$(CC) -o $@ $^ $(LIBS)
4147
$(RSYNC) : $(RSYNC_OBJS)
4248
$(CC) -o $@ $^ $(LIBS)
4349

@@ -56,5 +62,5 @@ new:
5662

5763
# make clean: Remove all generated file
5864
clean:
59-
rm -rf $(OBJS) $(CRONTAB) $(RSYNC)
65+
rm -rf $(OBJS) $(CRONTAB) $(CROND)$(RSYNC)
6066

‎common.h‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88
#include <unistd.h>
99
#include <stdbool.h>
1010

11-
#ifndef COMMON_H// Define guard
11+
#ifndef COMMON_H
1212
#define COMMON_H
1313

14-
// 1. 시스템 라이브러리
15-
// 2. 확장 라이브러리
16-
// 3. 프로젝트 라이브러리
17-
18-
// 매크로
14+
/**
15+
* @brief 버퍼 크기
16+
*/
1917
#define BUFFER_SIZE 256
2018
#define MAX_BUFFER_SIZE 1024
19+
20+
/**
21+
* @brief 파일 이름
22+
*/
23+
#define CRONTAB_FILE "ssu_crontab_file"
24+
#define CRONTAB_LOG "ssu_crontab_log"
25+
2126
#endif // COMMON_H

‎ssu_crond.c‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* @file ssu_crond.c
3+
* @brief ssu_crontab 프로그램
4+
* @author 김병준 (kbj9704@gmail.com)
5+
*/
6+
#include "ssu_crond.h"
7+
8+
#define DEBUG
9+
10+
/**
11+
* @brief ssu_crond 메인 함수
12+
*/
13+
int main(void)
14+
{
15+
printf("crond!\n");
16+
set_daemon_process();
17+
}
18+
19+
/**
20+
* @brief 데몬 프로세스 설정
21+
*/
22+
void set_daemon_process(void) // 데몬 프로세스 설정
23+
{
24+
pid_t pid;
25+
int fd, maxfd;
26+
27+
// #1 프로세스 분리
28+
if((pid = fork()) < 0) {
29+
fprintf(stderr, "fork error\n");
30+
exit(1);
31+
} else if(pid != 0)
32+
exit(0);
33+
34+
// #2 새로운 프로세스 그룹 생성
35+
setsid();
36+
37+
// #3 터미널 입출력 시그널 무시
38+
signal(SIGTTIN, SIG_IGN); // STDIN 무시
39+
signal(SIGTTOU, SIG_IGN); // STDOUT 무시
40+
signal(SIGTSTP, SIG_IGN); // STDERR 무시
41+
42+
// #4 파일 모드 생성 마스크 해제
43+
umask(false);
44+
45+
// #5 루트 디렉토리 이동
46+
chdir("/");
47+
48+
// #6 모든 파일 디스크럽터 연결 종료
49+
maxfd = getdtablesize(); // 모든 파일 디스크럽터 개수 획득
50+
for(fd = 0; fd < maxfd; fd++)
51+
close(fd);
52+
53+
// #7 표준 입출력 및 에러 재지정
54+
fd = open("dev/null", O_RDWR); // STDIO 재설정
55+
dup(0);
56+
dup(0);
57+
}
58+

‎ssu_crond.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @file ssu_crond.h
3+
* @brief ssu_crond.c에서 사용되는 라이브러리, 매크로, 프로토타입 선언
4+
* @author 김병준 (kbj9704@gmail.com)
5+
*/
6+
#ifndef SSU_CROND_H
7+
#define SSU_CROND_H
8+
9+
#include "common.h"
10+
#include <fcntl.h>
11+
#include <time.h>
12+
#include <sys/types.h>
13+
#include <sys/stat.h>
14+
15+
void set_daemon_process(void); // 데몬 프로세스 설정
16+
#endif // SSU_CROND_H

‎ssu_crontab.h‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#ifndef SSU_CRONTAB_H // Define Guard
77
#define SSU_CRONTAB_H
88

9+
#include "common.h"
910
#include <string.h>
1011
#include <ctype.h>
1112
#include <time.h>
12-
#include "common.h"
1313

1414
/**
1515
* @brief 명령어 타입 번호
@@ -29,12 +29,6 @@
2929
#define MONTH 4
3030
#define DAY_OF_WEEK 5
3131

32-
/**
33-
* @brief 파일 이름
34-
*/
35-
#define CRONTAB_FILE "ssu_crontab_file"
36-
#define CRONTAB_LOG "ssu_crontab_log"
37-
3832
typedef struct CommandTokenStruct // 프롬프트 명령행 토큰 구조체
3933
{
4034
int argc; // 인자 개수

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /