fix
This commit is contained in:
parent
9563cf2009
commit
0cbd2c4ed0
|
@ -0,0 +1 @@
|
|||
localhost
|
|
@ -1,9 +1,12 @@
|
|||
#!/bin/sh
|
||||
echo "Mounting.."
|
||||
echo "Mounting..."
|
||||
mount -o nosuid,noexec,nodev -t proc proc /proc
|
||||
mount -o nosuid,noexec,nodev -t sysfs sysfs /sys
|
||||
mount -o gid=5,mode=0620 -t devtmpfs /dev
|
||||
mount -o nosuid,noexec,nodev,mode=0777 -t tmpfs /tmp
|
||||
|
||||
echo "Setuping hostname..."
|
||||
hostname -c /etc/hostname
|
||||
|
||||
echo "Starting shell..."
|
||||
sh
|
||||
env TERM="vt100" sh
|
||||
|
|
|
@ -30,7 +30,8 @@ int nl(const char *path) {
|
|||
fprintf(stdout, "%*s\t%s", w_flag, " ", buf);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
if (buf != NULL)
|
||||
free(buf);
|
||||
|
||||
if (strcmp(path, "-"))
|
||||
fclose(fp);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "recurse.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "R")) != -1) {
|
||||
switch (opt) {
|
||||
default:
|
||||
printf("grep [pattern1 pattern2...]\n\t[-R Recursive]\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,18 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(const int argc, const char **argv) {
|
||||
if (argv[argc - 1][0] == '-') {
|
||||
printf("hostname [hostname Set new hostname]\n");
|
||||
return 0;
|
||||
void readcfg(const char *cfg, char *buf, size_t len) {
|
||||
FILE *fp = fopen(cfg, "r");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "hostname: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fgets(buf, len, fp);
|
||||
|
||||
/* Remove \n from string */
|
||||
*(strrchr(buf, '\n')) = '\0';
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char hostname[HOST_NAME_MAX + 1];
|
||||
char *newhost = NULL;
|
||||
int config = 0;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "c:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
readcfg(optarg, hostname, sizeof(hostname));
|
||||
|
||||
config = 1;
|
||||
newhost = hostname;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("hostname [hostname]\n\t[-c CONFIG Use config file]\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (newhost == NULL)
|
||||
newhost = argv[0];
|
||||
|
||||
/* Set hostname */
|
||||
if (argc == 2) {
|
||||
if (sethostname(argv[argc - 1], strlen(argv[argc - 1])) < 0) {
|
||||
if (argc == 1 || config) {
|
||||
if (sethostname(newhost, strlen(newhost)) < 0) {
|
||||
fprintf(stderr, "hostname: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
@ -20,8 +57,7 @@ int main(const int argc, const char **argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Get info */
|
||||
char hostname[HOST_NAME_MAX + 1];
|
||||
/* Get hostname */
|
||||
if (gethostname(hostname, sizeof(hostname)) < 0) {
|
||||
fprintf(stderr, "hostname: %s\n", strerror(errno));
|
||||
return 1;
|
||||
|
|
|
@ -36,7 +36,9 @@ int parse_fstab(void) {
|
|||
// ret = 1;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
if (buf != NULL)
|
||||
free(buf);
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue