Commits

Bryan O'Sullivan committed f6d3a74

Clarify flag checking.
Add early install code.

  • Participants
  • Parent commits 94ff30b

Comments (0)

Files changed (2)

-CFLAGS += -Wall -Werror -std=gnu99 -g -O2
+prefix ?= /
+bindir ?= $(prefix)/sbin
+etcdir ?= $(prefix)/etc/netplug
+
+CFLAGS += -Wall -Werror -std=gnu99 -g -DNP_ETC_DIR="$(etcdir)"
 
 netplug: config.o netlink.o lib.o if_info.o main.o
 	$(CC) -o $@ $^
 
 clean:
 	-rm -f netplug *.o
+
+install: $(bindir)/netplug $(etcdir)/netplug.conf
+	@:
+
+$(bindir)/netplug: netplug
+	install -o root -g root -m 755 $^ $@
+
+$(etcdir)/netplug.conf: $(etcdir)
+	echo 'eth*' > $@
+	chown root.root $@
+	chmod 644 $@
+
+$(etcdir):
+	install -d -o root -g root -m 755 $@
 }
 
 
+#define flag_was_set(flag) \
+	(!(i->flags & (flag)) && (info->ifi_flags & (flag)))
+#define flag_was_unset(flag) \
+	((i->flags & (flag)) && !(info->ifi_flags & (flag)))
+
 static int
 handle_interface(struct nlmsghdr *hdr, void *arg)
 {
 	return -1;
     }
 
+    if (i->flags == info->ifi_flags) {
+	goto done;
+    }
+    
     char *name = RTA_DATA(attrs[IFLA_IFNAME]);
 
     if (!if_match(name)) {
 	goto done;
     }
     
-    if (i->flags == info->ifi_flags) {
-	goto done;
-    }
-    
     printf("%s: flags 0x%08x -> 0x%08x\n", name, i->flags, info->ifi_flags);
 
-    if (info->ifi_flags & IFF_UP) {
+    if (flag_was_set(IFF_RUNNING)) {
 	run_hotplug(name);
-    } else {
+    }
+    if (flag_was_unset(IFF_UP)) {
 	if (try_probe(name) == 0) {
 	    fprintf(stderr, "Warning: Could not bring %s back up\n", name);
 	}
     }
     
     if (!cfg_read) {
-	read_config("/etc/netplug/netplug.conf");
+	read_config(NP_ETC_DIR "/netplug.conf");
     }
     
     if (getuid() != 0) {