移植goahead到ucLinux注意事项

  • fork()改为vfork()
  • gethostbyname()改为intaddr.s_addr = inet_addr("192.168.1.100"); // 板子IP
  • https://www.linuxidc.com/Linux/2011-01/31076.htm
  • https://wenku.baidu.com/view/fcf960addd3383c4bb4cd29a.html

我的亲身经历

  • ucLinux下新增uclibc库,编译并安装uclibc的方法参考《building uClibc.pdf》
  • 我用的goahead-5.1.0,里面没有fork(),全是vfork()。
  • 注释掉IPv6
  • 在src/goahead.h里定义ME_COMPILER_HAS_SIGNLE_STACK
  • 注释掉src/http.c/websOpen()里的setFileLimits()调用。
PUBLIC int websOpen(cchar *documents, cchar *routeFile)
{
   WebsMime    *mt;

   webs = NULL;
   websMax = 0;

   error( "---> websOpen()\n");
   websOsOpen();
   websRuntimeOpen();
   websTimeOpen();
   websFsOpen();
   logOpen();
//    setFileLimits();
   socketOpen();
   if (setLocalHost() < 0) {
       return -1;
   }
  • 修改src/socket.c/socketOpen()里的AF_INET6AF_INET,设置hasIPv6 = 0
- PUBLIC int socketOpen(void)
{
  Socket  fd;

  if (++socketOpenCount > 1) {
      return 0;
  }

//#if ME_WIN_LIKE
//{
//    WSADATA     wsaData;
//    if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {
//        return -1;
//    }
//    if (wsaData.wVersion != MAKEWORD(1,1)) {
//        WSACleanup();
//        return -1;
//    }
//}
//#endif
  socketList = NULL;
  socketMax = 0;
  socketHighestFd = -1;
  error("---> socketOpen\n");
  if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) {
      closesocket(fd);
  } else {
      trace(1, "This system does not have IPv6 support");
  }
  hasIPv6 = 0;
  return 0;
}
  • 新增源文件的方法
    在src目录下创建usercode目录,把新文件放在src/usercode/xxxx.c目录下。然后修改projects/goahead-linux-static.mk将新文件编译进去。
    例如我新增一个hello.c hello.h,在goahead.c中调用。
[root@localhost usercode]# pwd
/goahead-5.1.0/src/usercode
[root@localhost usercode]# ls
hello.c  hello.h
 《hello.c》
#include 

void showhello(void)
{
	error("hello jimbo");
}
《hello.h》
#include "goahead.h"
void showhello(void);
《goahead.c》
/********************************* Includes ***********************************/
#include    "goahead.h"
#include	"hello.h"	//包含头文件
省略。。。
MAIN(goahead, int argc, char **argv, char **envp)
{
    char    *argp, *home, *documents, *endpoints, *endpoint, *route, *auth, *tok, *lspec;
    int     argind;

	showhello();		//调用

#if WINDOWS
    if (windowsInit() < 0) {
        return 0;
    }
#endif
《goahead-linux-static.mk》修改3处
#
#   mbedtls.h
#
DEPS_6 += src/mbedtls/mbedtls.h

$(BUILD)/inc/mbedtls.h: $(DEPS_6)
	@echo '      [Copy] $(BUILD)/inc/mbedtls.h'
	mkdir -p "$(BUILD)/inc"
	cp src/mbedtls/mbedtls.h $(BUILD)/inc/mbedtls.h

//新增
#	usercode
DEPS_USER_H1 += src/usercode/hello.h
DEPS_USER_H1 += $(BUILD)/inc/goahead.h

$(BUILD)/inc/hello.h: $(DEPS_USER_H1)
	@echo '      [Copy] $(BUILD)/inc/hello.h'
	mkdir -p "$(BUILD)/inc"
	cp src/usercode/hello.h $(BUILD)/inc/hello.h

省略。。。

#
#   upload.o
#
DEPS_32 += $(BUILD)/inc/goahead.h

$(BUILD)/obj/upload.o: \
    src/upload.c $(DEPS_32)
	@echo '   [Compile] $(BUILD)/obj/upload.o'
	$(CC) -c -o $(BUILD)/obj/upload.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" -DME_COM_OPENSSL_PATH=$(ME_COM_OPENSSL_PATH) $(IFLAGS) "-I$(ME_COM_OPENSSL_PATH)/include" src/upload.c

//新增
#	usercode
DEPS_USER_C1 += $(BUILD)/inc/goahead.h
DEPS_USER_C1 += $(BUILD)/inc/hello.h

$(BUILD)/obj/hello.o: \
    src/usercode/hello.c $(DEPS_USER_C1)
	@echo '   [Compile] $(BUILD)/obj/hello.o'
	$(CC) -c -o $(BUILD)/obj/hello.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" -DME_COM_OPENSSL_PATH=$(ME_COM_OPENSSL_PATH) $(IFLAGS) "-I$(ME_COM_OPENSSL_PATH)/include" src/usercode/hello.c

省略。。。

#
#   libgo
#
DEPS_36 += $(BUILD)/inc/osdep.h
ifeq ($(ME_COM_MBEDTLS),1)
    DEPS_36 += $(BUILD)/bin/libgoahead-mbedtls.a
endif
ifeq ($(ME_COM_OPENSSL),1)
    DEPS_36 += $(BUILD)/bin/libgoahead-openssl.a
endif
DEPS_36 += $(BUILD)/inc/goahead.h
DEPS_36 += $(BUILD)/inc/js.h
DEPS_36 += $(BUILD)/obj/action.o
DEPS_36 += $(BUILD)/obj/alloc.o
DEPS_36 += $(BUILD)/obj/auth.o
DEPS_36 += $(BUILD)/obj/cgi.o
DEPS_36 += $(BUILD)/obj/crypt.o
DEPS_36 += $(BUILD)/obj/file.o
DEPS_36 += $(BUILD)/obj/fs.o
DEPS_36 += $(BUILD)/obj/http.o
DEPS_36 += $(BUILD)/obj/js.o
DEPS_36 += $(BUILD)/obj/jst.o
DEPS_36 += $(BUILD)/obj/options.o
DEPS_36 += $(BUILD)/obj/osdep.o
DEPS_36 += $(BUILD)/obj/rom.o
DEPS_36 += $(BUILD)/obj/route.o
DEPS_36 += $(BUILD)/obj/runtime.o
DEPS_36 += $(BUILD)/obj/socket.o
DEPS_36 += $(BUILD)/obj/time.o
DEPS_36 += $(BUILD)/obj/upload.o
DEPS_36 += $(BUILD)/obj/hello.o	//新增

$(BUILD)/bin/libgo.a: $(DEPS_36)
	@echo '      [Link] $(BUILD)/bin/libgo.a'
	$(AR) -cr $(BUILD)/bin/libgo.a "$(BUILD)/obj/action.o" "$(BUILD)/obj/alloc.o" "$(BUILD)/obj/auth.o" "$(BUILD)/obj/cgi.o" "$(BUILD)/obj/crypt.o" "$(BUILD)/obj/file.o" "$(BUILD)/obj/fs.o" "$(BUILD)/obj/http.o" "$(BUILD)/obj/js.o" "$(BUILD)/obj/jst.o" "$(BUILD)/obj/options.o" "$(BUILD)/obj/osdep.o" "$(BUILD)/obj/rom.o" "$(BUILD)/obj/route.o" "$(BUILD)/obj/runtime.o" "$(BUILD)/obj/socket.o" "$(BUILD)/obj/time.o" "$(BUILD)/obj/upload.o" "$(BUILD)/obj/hello.o"	//新增

编译运行goahead

[root@localhost goahead-5.1.0]# build/linux-x86-static/bin/goahead -v --home /etc/goahead/ /var/www/goahead/
goahead: 0: hello jimbo		//调用
goahead: 2: Configuration for Embedthis GoAhead Community Edition
goahead: 2: ---------------------------------------------
goahead: 2: Version:            5.1.0
goahead: 2: BuildType:          Debug
goahead: 2: CPU:                x86
goahead: 2: OS:                 linux
goahead: 2: Host:               127.0.0.1
goahead: 2: Directory:          /etc/goahead
goahead: 2: Documents:          /var/www/goahead/
goahead: 2: Configure:          me -d -q -platform linux-x86-static -static -configure . -gen make
goahead: 2: ---------------------------------------------
goahead: 2: Started http://*:80
goahead: 2: Started https://*:443

你可能感兴趣的:(移植goahead到ucLinux注意事项)