m********r 发帖数: 334 | 1 这段程序读boa的配置文件boa.conf,找到端口号后改写新端口,例如
Port 80
# Listen: the Internet address to bind(2) to. If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY). You only get one "Listen" directive,
变成Port 8080
# Listen: the Internet address to bind(2) to. If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY). You only get one "Listen" directive,
现在发现每次第一次修改的时候这一行没问题,但是下面的注释的#号没有了,变成
n: the Internet address to bind(2) to. If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY). You only get one "Listen" directive,
boa无法重新运行,手动改过来以后就没有问题,但是为什么第一次就不行?
system("/usr/bin/killall boa");
boa=fopen("/etc/boa.conf","rt+");
while(fgets(buf,255,boa)!= NULL)
{
if(buf[0]=='#')
continue;
p=strstr(buf,"Port ");
if(p) {
fseek(boa, (-1)*strlen(buf), SEEK_CUR);
sprintf(buf,"Port %5d\n",runtime.cm.http_port);
fputs(buf,boa);
break;
}
}
fclose(boa);
sprintf(buf, "/usr/sbin/boa -c /etc");
system(buf); | t****t 发帖数: 6806 | 2 because there is no way to "insert" something into a file. you have to read
the rest of the file first, insert whatever you want, and write back the
rest.
【在 m********r 的大作中提到】 : 这段程序读boa的配置文件boa.conf,找到端口号后改写新端口,例如 : Port 80 : # Listen: the Internet address to bind(2) to. If you leave it out, : # it takes the behavior before 0.93.17.2, which is to bind to all : # addresses (INADDR_ANY). You only get one "Listen" directive, : 变成Port 8080 : # Listen: the Internet address to bind(2) to. If you leave it out, : # it takes the behavior before 0.93.17.2, which is to bind to all : # addresses (INADDR_ANY). You only get one "Listen" directive, : 现在发现每次第一次修改的时候这一行没问题,但是下面的注释的#号没有了,变成
| m*****e 发帖数: 4193 | 3 You cannot modify the source file. Write a new file and rename to the
original.
【在 m********r 的大作中提到】 : 这段程序读boa的配置文件boa.conf,找到端口号后改写新端口,例如 : Port 80 : # Listen: the Internet address to bind(2) to. If you leave it out, : # it takes the behavior before 0.93.17.2, which is to bind to all : # addresses (INADDR_ANY). You only get one "Listen" directive, : 变成Port 8080 : # Listen: the Internet address to bind(2) to. If you leave it out, : # it takes the behavior before 0.93.17.2, which is to bind to all : # addresses (INADDR_ANY). You only get one "Listen" directive, : 现在发现每次第一次修改的时候这一行没问题,但是下面的注释的#号没有了,变成
| t****t 发帖数: 6806 | 4 oh you can modify it, just no insertion and deletion. that's hardly useful
though.
【在 m*****e 的大作中提到】 : You cannot modify the source file. Write a new file and rename to the : original.
| m********r 发帖数: 334 | 5 那为什么以后同样的操作后面的注释没有被覆盖?
read
【在 t****t 的大作中提到】 : because there is no way to "insert" something into a file. you have to read : the rest of the file first, insert whatever you want, and write back the : rest.
| m********r 发帖数: 334 | 6 修改这种配置文件用C有什么更方便的办法?
【在 m*****e 的大作中提到】 : You cannot modify the source file. Write a new file and rename to the : original.
| t****t 发帖数: 6806 | 7 from "80" to "8080": 2->4, insert 2 byte (not allowed)
from "8080" to "8080": 4->4, no insertion
【在 m********r 的大作中提到】 : 那为什么以后同样的操作后面的注释没有被覆盖? : : read
| t****t 发帖数: 6806 | 8 you need perl.
【在 m********r 的大作中提到】 : 修改这种配置文件用C有什么更方便的办法?
|
|