리눅스에서 patch 파일을 만드는 방법입니다.

– 사용법

diff -uN [원본파일] [수정파일] > [저장 될 패치 파일]

필자는 vsftpd 2.3.0 버전에서 한글이 로그에서 물음표(?)로 표시되는 것과 SSL을 사용할수 있도록 패치 해보았습니다.

[[email protected] ~]# cd /usr/local/src/vsftpd-2.3.0
[[email protected] ~]# diff -uN builddefs.h builddefs_patch.h > vsftpd-hangul-log.patch
[[email protected] ~]# diff -uN logging.c logging_patch.c >> vsftpd-hangul-log.patch
[[email protected] ~]# diff -uN postlogin.c postlogin_patch.c >> vsftpd-hangul-log.patch
[[email protected] ~]# cat vsftpd-hangul-log.patch

— builddefs.h    2010-08-06 09:50:31.000000000 +0900
+++ builddefs_patch.h    2010-08-26 23:45:41.000000000 +0900
@@ -3,7 +3,7 @@
 
 #undef VSF_BUILD_TCPWRAPPERS
 #define VSF_BUILD_PAM
-#undef VSF_BUILD_SSL
+#define VSF_BUILD_SSL
 
 #endif /* VSF_BUILDDEFS_H */
 
— logging.c    2009-10-19 12:24:23.000000000 +0900
+++ logging_patch.c    2010-08-26 23:46:10.000000000 +0900
@@ -159,7 +159,7 @@
       return;
     }
   }
–  str_replace_unprintable(p_str, ‘?’);
+  /* str_replace_unprintable(p_str, ‘?’); */
   str_append_char(p_str, ‘\n’);
   /* Ignore write failure; maybe the disk filled etc. */
   (void) str_write_loop(p_str, fd);
— postlogin.c    2010-03-26 13:01:06.000000000 +0900
+++ postlogin_patch.c    2010-08-26 23:47:05.000000000 +0900
@@ -129,7 +129,7 @@
         str_append_str(&proctitle_str, &p_sess->ftp_arg_str);
       }
       /* Suggestion from Solar */
–      str_replace_unprintable(&proctitle_str, ‘?’);
+      /* str_replace_unprintable(&proctitle_str, ‘?’); */
       vsf_sysutil_setproctitle_str(&proctitle_str);
       str_free(&proctitle_str);
     }

– patch 방법

[[email protected] ~]# cd /usr/local/src/vsftpd-2.3.0
[[email protected] ~]# patch -p0 < vsftpd-hangul-log.patch

Hmm…  Looks like a unified diff to me…
The text leading up to this was:
————————–
|— builddefs.h        2010-08-06 09:50:31.000000000 +0900
|+++ builddefs_patch.h  2010-08-26 23:45:41.000000000 +0900
————————–
Patching file builddefs.h using Plan A…
Hunk #1 succeeded at 3.
Hmm…  The next patch looks like a unified diff to me…
The text leading up to this was:
————————–
|— logging.c  2009-10-19 12:24:23.000000000 +0900
|+++ logging_patch.c    2010-08-26 23:46:10.000000000 +0900
————————–
Patching file logging.c using Plan A…
Hunk #1 succeeded at 159.
Hmm…  The next patch looks like a unified diff to me…
The text leading up to this was:
————————–
|— postlogin.c        2010-03-26 13:01:06.000000000 +0900
|+++ postlogin_patch.c  2010-08-26 23:47:05.000000000 +0900
————————–
Patching file postlogin.c using Plan A…
Hunk #1 succeeded at 129.
done