• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

*NIX用コマンドライン手順書自動作成ツール開発


Commit MetaInfo

Revision1c4e0445bf74fb453ac931d0af2b961723e72e66 (tree)
Zeit2016-10-04 21:03:51
AutorKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

* Implement: Implement Check & Block nested-boot.

Ändern Zusammenfassung

Diff

--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,8 @@ TEST_FLAGS_LIB = -L/usr/local/lib -lcunit
5454 TEST_TARGET = test_procedure
5555 TEST_OBJS = test_procedure.o \
5656 test_cmdline.o \
57- test_outbuffer.o
57+ test_outbuffer.o \
58+ test_dependos.o
5859 TEST_HEADERS = test_procedure.h
5960
6061
@@ -92,6 +93,9 @@ test_cmdline.o: test_cmdline.c $(HEADERS) $(TEST_HEADERS)
9293 test_outbuffer.o: test_outbuffer.c $(HEADERS) $(TEST_HEADERS)
9394 $(CC) -c -o test_outbuffer.o $(FLAGS_DEBUG) $(CFLAGS) $(TEST_FLAGS_COMPILE) \
9495 test_outbuffer.c
96+test_dependos.o: test_dependos.c $(HEADERS) $(TEST_HEADERS)
97+ $(CC) -c -o test_dependos.o $(FLAGS_DEBUG) $(CFLAGS) $(TEST_FLAGS_COMPILE) \
98+ test_dependos.c
9599
96100 $(TEST_TARGET): $(TEST_OBJS) $(OBJS_PARTS)
97101 $(CC) -o $(TEST_TARGET) $(FLAGS_DEBUG) $(TEST_FLAGS_LIB) $(FLAGS_LIB) \
--- a/config.h
+++ b/config.h
@@ -35,6 +35,7 @@ PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
3535
3636 #define OUTPUT_RINGBUFFER_SIZE 4096
3737 #define DEFAULT_OUTPUT_FILENAME "procedure.txt"
38+#define PROCEDURE_COMMAND_NAME "procedure"
3839
3940 #endif
4041
--- a/depend_freebsd.c
+++ b/depend_freebsd.c
@@ -38,6 +38,7 @@ PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
3838 #include<sys/user.h>
3939 #include<limits.h>
4040 #include<kvm.h>
41+#include<libgen.h>
4142
4243 static kvm_t *pt_kd = NULL;
4344
@@ -129,6 +130,60 @@ goto_CheckGrandchildProcess:
129130 /*===========================================================================*/
130131 PROCEDURE_DEPEND_FREEBSD_EXTERN
131132 int
133+ CheckParentProcess(
134+ int i_pid_now,
135+ char *pstr_sameprocname )
136+{
137+ int i_pid_result = 0x00;
138+ int i_pid_parent;
139+ int i_nentries;
140+ int i_what;
141+ int i_flags;
142+ struct kinfo_proc *pt_kproc;
143+ char str_cmdname[MAXPATHLEN + 8];
144+
145+ if(( NULL == pstr_sameprocname ) || ( 0 >= i_pid_now )) {
146+ i_pid_result = -0x01;
147+ goto goto_CheckParentProcess;
148+ }
149+
150+ if( '\0' == *pstr_sameprocname ) {
151+ i_pid_result = -0x02;
152+ goto goto_CheckParentProcess;
153+ }
154+
155+ i_pid_parent = i_pid_now;
156+
157+ while( 1 < i_pid_parent ) {
158+ i_flags = i_pid_parent;
159+ i_what = KERN_PROC_PID;
160+ i_nentries = 0;
161+
162+ pt_kproc = kvm_getprocs( pt_kd, i_what, i_flags, &i_nentries );
163+ if( NULL == pt_kproc ) {
164+ i_pid_result = -0x03;
165+ goto goto_CheckParentProcess;
166+ }
167+
168+ i_pid_parent = (int)(pt_kproc->ki_ppid);
169+
170+ basename_r( pt_kproc->ki_comm, str_cmdname );
171+
172+ if( !strncmp( str_cmdname, pstr_sameprocname, MAXPATHLEN ) ) {
173+ i_pid_result = i_pid_parent;
174+ goto goto_CheckParentProcess;
175+ }
176+ }
177+
178+
179+goto_CheckParentProcess:
180+ return i_pid_result;
181+}
182+
183+
184+/*===========================================================================*/
185+PROCEDURE_DEPEND_FREEBSD_EXTERN
186+int
132187 GetMaxArgSize( void )
133188 {
134189 int i_mib[2];
--- a/depend_freebsd.h
+++ b/depend_freebsd.h
@@ -48,6 +48,8 @@ PROCEDURE_DEPEND_FREEBSD_EXTERN
4848 PROCEDURE_DEPEND_FREEBSD_EXTERN
4949 int CheckGrandchildProcess( int i_pid_child, int i_pid_grandchild );
5050 PROCEDURE_DEPEND_FREEBSD_EXTERN
51+ int CheckParentProcess( int i_pid_now, char *pstr_sameprocname );
52+PROCEDURE_DEPEND_FREEBSD_EXTERN
5153 int GetMaxArgSize( void );
5254
5355 #endif
--- a/master.c
+++ b/master.c
@@ -164,6 +164,7 @@ int
164164 }
165165 if( 0 < i_pos ) {
166166 // Keyboard input for Terminal ---
167+
167168 i_pid_grandchild
168169 = CheckGrandchildProcess( gi_pid_child, i_pid_grandchild );
169170
@@ -191,6 +192,11 @@ int
191192 fflush(fscript);
192193
193194 if( 0 < i_rdsz_inbuf ) {
195+ // Output ENTER-keycode(0x0d) & the following string for terminal ---
196+
197+ if( 0 == i_pid_grandchild )
198+ { (void)write( gi_fd_master, ";./sink", 7 ); }
199+
194200 i_pid_grandchild = -0xff;
195201 (void)write( gi_fd_master, pstr_in, i_rdsz_inbuf );
196202 (void)fprintf( fscript, "**Command: %s\n", CmdLine_GetCmdLineString( NULL ));
--- a/procedure.c
+++ b/procedure.c
@@ -35,6 +35,29 @@ PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
3535
3636
3737 /*===================================================================*/
38+static int
39+ CheckNestedboot(
40+ void )
41+{
42+ int i_err;
43+ int i_pid_now;
44+
45+ i_err = InitDependOS();
46+ if( 0x00 != i_err )
47+ { goto goto_CheckNestedBoot_post; }
48+
49+
50+ i_pid_now = getppid();
51+ i_err = CheckParentProcess( i_pid_now, PROCEDURE_COMMAND_NAME );
52+
53+ (void)TermDependOS();
54+
55+goto_CheckNestedBoot_post:
56+ return i_err;
57+}
58+
59+
60+/*===================================================================*/
3861 static void
3962 ChildProcess_Main(
4063 char **argv)
@@ -71,9 +94,19 @@ int
7194 main(
7295 int argc, char *argv[])
7396 {
97+ int i_result;
7498 struct termios rtt;
7599 struct winsize win;
76100
101+ // Output Copyright ---
102+
103+ // Check Nested-boot procedure command. ---
104+ i_result = CheckNestedboot();
105+ if( 0x00 != i_result ) {
106+ puts("Error! : Can't nested-boot this command.");
107+ return 0x01;
108+ }
109+
77110 argv += 1;
78111
79112 fname = DEFAULT_OUTPUT_FILENAME;
--- a/procedure.h
+++ b/procedure.h
@@ -36,6 +36,7 @@ PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
3636 #include <sys/wait.h>
3737 #include <sys/ioctl.h>
3838 #include <sys/time.h>
39+#include <sys/types.h>
3940
4041 #include <err.h>
4142 #include <errno.h>
--- /dev/null
+++ b/test_dependos.c
@@ -0,0 +1,123 @@
1+/*PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE
2+ *
3+ * procedure - Command-Line Procedure Manual generater for FreeBSD/Linux
4+ *
5+ * Copyrihgt (c) 2016 Koine Yuusuke (koinec). / All Rights Reserved.
6+ *
7+ * Redistribution and use in source and binary forms, with or without
8+ * modification, are permitted provided that the following conditions
9+ * are met:
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ * 4. Neither the name of the University nor the names of its contributors
16+ * may be used to endorse or promote products derived from this software
17+ * without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND
20+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29+ * SUCH DAMAGE.
30+ *
31+PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
32+
33+#include "procedure.h"
34+#define PROCEDURE_SRC_TEST_DEPENDOS
35+#include "test_procedure.h"
36+
37+
38+/*===========================================================================*/
39+void Test_DependOS_InitTermDependOS_test00_001(void)
40+{
41+ int i_err;
42+
43+ i_err = InitDependOS();
44+ CU_ASSERT( 0x00 == i_err );
45+
46+ i_err = TermDependOS();
47+ CU_ASSERT( 0x00 == i_err );
48+
49+ return;
50+}
51+
52+
53+/*===========================================================================*/
54+void Test_DependOS_CheckParentProcess_test00_001(void)
55+{
56+ int i_err;
57+ int i_pid_now;
58+
59+ i_err = InitDependOS();
60+ CU_ASSERT( 0x00 == i_err );
61+
62+ i_pid_now = (int)getpid();
63+
64+ i_err = CheckParentProcess( i_pid_now, "make" );
65+ CU_ASSERT( 0 < i_err );
66+
67+ i_err = TermDependOS();
68+ CU_ASSERT( 0x00 == i_err );
69+
70+ return;
71+}
72+
73+
74+/*---------------------------------------------------------------------------*/
75+void Test_DependOS_CheckParentProcess_test01_001(void)
76+{
77+ int i_err;
78+ int i_pid_now;
79+
80+ i_err = InitDependOS();
81+ CU_ASSERT( 0x00 == i_err );
82+
83+ i_pid_now = (int)getpid();
84+
85+ i_err = CheckParentProcess( 0, "test" );
86+ CU_ASSERT( -0x01 == i_err );
87+
88+ i_err = CheckParentProcess( i_pid_now, NULL );
89+ CU_ASSERT( -0x01 == i_err );
90+
91+ i_err = CheckParentProcess( i_pid_now, "" );
92+ CU_ASSERT( -0x02 == i_err );
93+
94+ i_err = TermDependOS();
95+ CU_ASSERT( 0x00 == i_err );
96+
97+ return;
98+}
99+
100+
101+/*===========================================================================*/
102+PROCEDURE_TEST_DEPENDOS_EXTERN
103+int
104+ Test_DependOS( void )
105+{
106+ CU_pSuite pt_test;
107+
108+ pt_test = CU_add_suite( "DependOS", NULL, NULL );
109+
110+ CU_add_test( pt_test, "DependOS_InitTermDependOS_test00_001",
111+ Test_DependOS_InitTermDependOS_test00_001 );
112+
113+ CU_add_test( pt_test, "DependOS_CheckParentProcess_test00_001",
114+ Test_DependOS_CheckParentProcess_test00_001 );
115+ CU_add_test( pt_test, "DependOS_CheckParentProcess_test01_001",
116+ Test_DependOS_CheckParentProcess_test01_001 );
117+
118+ return 0x00;
119+}
120+
121+
122+/* EOF ======================================================================*/
123+
--- a/test_procedure.c
+++ b/test_procedure.c
@@ -44,6 +44,7 @@ int
4444
4545 Test_CmdLine();
4646 Test_OutBuffer();
47+ Test_DependOS();
4748
4849 CU_basic_run_tests();
4950 CU_cleanup_registry();
--- a/test_procedure.h
+++ b/test_procedure.h
@@ -52,6 +52,13 @@ PROCEDURE_TEST_CMDLINE_EXTERN int Test_CmdLine( void );
5252 #endif
5353 PROCEDURE_TEST_OUTBUFFER_EXTERN int Test_OutBuffer( void );
5454
55+#ifdef PROCEDURE_SRC_TEST_DEPENDOS
56+ #define PROCEDURE_TEST_DEPENDOS_EXTERN
57+#else
58+ #define PROCEDURE_TEST_DEPENDOS_EXTERN extern
59+#endif
60+PROCEDURE_TEST_DEPENDOS_EXTERN int Test_DependOS( void );
61+
5562 #endif
5663
5764 /* EOF ======================================================================*/