Hex Artifact Content

Artifact e85e3209232ac90a68783d41b3ad720d6153c04c:


0000: 66 69 6c 65 64 0a 3d 3d 3d 3d 3d 0a 0a 49 6e 74  filed.=====..Int
0010: 72 6f 64 75 63 74 69 6f 6e 0a 2d 2d 2d 2d 2d 2d  roduction.------
0020: 2d 2d 2d 2d 2d 2d 0a 22 66 69 6c 65 64 22 20 69  ------."filed" i
0030: 73 20 61 20 73 69 6d 70 6c 65 20 48 54 54 50 20  s a simple HTTP 
0040: 73 65 72 76 65 72 20 66 6f 72 20 73 65 72 76 69  server for servi
0050: 6e 67 20 6c 6f 63 61 6c 20 73 74 61 74 69 63 20  ng local static 
0060: 66 69 6c 65 73 20 6f 76 65 72 20 48 54 54 50 20  files over HTTP 
0070: 66 72 6f 6d 0a 4c 69 6e 75 78 2e 20 49 74 20 64  from.Linux. It d
0080: 6f 65 73 20 74 68 65 20 6c 65 61 73 74 20 61 6d  oes the least am
0090: 6f 75 6e 74 20 6f 66 20 65 66 66 6f 72 74 20 70  ount of effort p
00a0: 6f 73 73 69 62 6c 65 20 74 6f 20 67 65 74 20 74  ossible to get t
00b0: 6f 20 74 68 65 20 70 6f 69 6e 74 20 6f 66 0a 68  o the point of.h
00c0: 61 6e 64 69 6e 67 20 74 68 65 20 61 63 74 75 61  anding the actua
00d0: 6c 20 74 72 61 6e 73 66 65 72 20 6f 76 65 72 20  l transfer over 
00e0: 74 6f 20 74 68 65 20 6b 65 72 6e 65 6c 2e 0a 0a  to the kernel...
00f0: 49 74 20 69 73 20 6d 75 6c 74 69 74 68 72 65 61  It is multithrea
0100: 64 65 64 20 77 68 65 72 65 20 65 76 65 72 79 20  ded where every 
0110: 74 68 72 65 61 64 20 73 65 72 76 69 63 65 73 20  thread services 
0120: 61 20 73 69 6e 67 6c 65 20 63 6f 6e 63 75 72 72  a single concurr
0130: 65 6e 74 20 63 6c 69 65 6e 74 2e 0a 49 74 20 61  ent client..It a
0140: 74 74 65 6d 70 74 73 20 74 6f 20 72 65 64 75 63  ttempts to reduc
0150: 65 20 6c 61 74 65 6e 63 79 20 62 79 20 63 61 63  e latency by cac
0160: 68 69 6e 67 20 6f 70 65 6e 20 66 69 6c 65 20 64  hing open file d
0170: 65 73 63 72 69 70 74 6f 72 73 20 61 73 20 77 65  escriptors as we
0180: 6c 6c 2e 0a 0a 49 74 20 68 61 73 20 6e 6f 20 63  ll...It has no c
0190: 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 66 69 6c  onfiguration fil
01a0: 65 20 61 6e 64 20 73 75 70 70 6f 72 74 73 20 6f  e and supports o
01b0: 6e 6c 79 20 6d 69 6e 69 6d 61 6c 20 63 6f 6e 66  nly minimal conf
01c0: 69 67 75 72 61 74 69 6f 6e 2e 0a 4f 70 65 72 61  iguration..Opera
01d0: 74 69 6f 6e 20 69 73 20 64 65 73 63 72 69 62 65  tion is describe
01e0: 64 20 69 6e 20 74 68 65 20 6d 61 6e 75 61 6c 20  d in the manual 
01f0: 70 61 67 65 2e 0a 0a 55 73 61 67 65 0a 2d 2d 2d  page...Usage.---
0200: 2d 2d 0a 54 68 65 20 73 69 6d 70 6c 65 73 74 20  --.The simplest 
0210: 75 73 61 67 65 20 6f 66 20 22 66 69 6c 65 64 22  usage of "filed"
0220: 20 69 73 20 74 6f 20 72 75 6e 20 69 74 20 77 69   is to run it wi
0230: 74 68 20 6e 6f 20 61 72 67 75 6d 65 6e 74 73 2e  th no arguments.
0240: 20 20 54 68 69 73 20 77 69 6c 6c 20 73 74 61 72    This will star
0250: 74 0a 75 70 20 61 6e 20 48 54 54 50 20 73 65 72  t.up an HTTP ser
0260: 76 65 72 20 6c 69 73 74 65 6e 69 6e 67 20 6f 6e  ver listening on
0270: 20 70 6f 72 74 20 38 30 20 61 6e 64 20 73 68 61   port 80 and sha
0280: 72 69 6e 67 20 6f 75 74 20 74 68 65 20 72 6f 6f  ring out the roo
0290: 74 20 66 69 6c 65 73 79 73 74 65 6d 20 66 6f 72  t filesystem for
02a0: 0a 74 68 65 20 73 79 73 74 65 6d 20 61 73 20 74  .the system as t
02b0: 68 65 20 63 75 72 72 65 6e 74 20 75 73 65 72 2e  he current user.
02c0: 20 20 59 6f 75 20 70 72 6f 62 61 62 6c 79 20 64    You probably d
02d0: 6f 20 6e 6f 74 20 77 61 6e 74 20 74 6f 20 73 68  o not want to sh
02e0: 61 72 65 20 6f 75 74 20 79 6f 75 72 0a 72 6f 6f  are out your.roo
02f0: 74 20 66 69 6c 65 73 79 73 74 65 6d 20 73 69 6e  t filesystem sin
0300: 63 65 20 74 68 61 74 20 77 69 6c 6c 20 65 78 70  ce that will exp
0310: 6f 73 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20  ose information 
0320: 73 75 63 68 20 61 73 20 22 2f 65 74 63 2f 70 61  such as "/etc/pa
0330: 73 73 77 64 22 20 74 6f 0a 61 6e 6f 6e 79 6d 6f  sswd" to.anonymo
0340: 75 73 20 61 63 63 65 73 73 2e 20 20 59 6f 75 20  us access.  You 
0350: 70 72 6f 62 61 62 6c 79 20 61 6c 73 6f 20 64 6f  probably also do
0360: 6e 27 74 20 77 61 6e 74 20 74 6f 20 64 6f 20 74  n't want to do t
0370: 68 61 74 20 61 73 20 72 6f 6f 74 20 73 69 6e 63  hat as root sinc
0380: 65 20 74 68 65 6e 0a 73 65 6e 73 69 74 69 76 65  e then.sensitive
0390: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 73 75 63   information suc
03a0: 68 20 61 73 20 22 2f 65 74 63 2f 73 68 61 64 6f  h as "/etc/shado
03b0: 77 22 20 63 6f 75 6c 64 20 62 65 20 75 73 65 64  w" could be used
03c0: 20 74 6f 20 63 6f 6d 70 72 6f 6d 69 73 65 20 74   to compromise t
03d0: 68 65 0a 73 79 73 74 65 6d 2e 0a 0a 54 68 65 72  he.system...Ther
03e0: 65 66 6f 72 65 2c 20 74 68 65 20 22 2d 2d 75 73  efore, the "--us
03f0: 65 72 22 20 61 6e 64 20 22 2d 2d 72 6f 6f 74 22  er" and "--root"
0400: 20 6f 70 74 69 6f 6e 73 20 73 68 6f 75 6c 64 20   options should 
0410: 62 65 20 75 73 65 64 20 74 6f 20 73 70 65 63 69  be used to speci
0420: 66 79 20 61 20 75 73 65 72 0a 66 6f 72 20 22 66  fy a user.for "f
0430: 69 6c 65 64 22 20 74 6f 20 72 75 6e 20 61 73 20  iled" to run as 
0440: 69 6e 20 61 64 64 69 74 69 6f 6e 20 74 6f 20 61  in addition to a
0450: 20 64 69 72 65 63 74 6f 72 79 20 74 6f 20 63 68   directory to ch
0460: 61 6e 67 65 20 72 6f 6f 74 20 28 63 68 72 6f 6f  ange root (chroo
0470: 74 28 32 29 29 20 74 6f 0a 70 72 69 6f 72 20 74  t(2)) to.prior t
0480: 6f 20 73 65 72 76 69 6e 67 20 6f 75 74 20 66 69  o serving out fi
0490: 6c 65 73 2e 0a 0a 45 78 61 6d 70 6c 65 20 31 2c  les...Example 1,
04a0: 20 69 6e 73 65 63 75 72 65 20 66 69 6c 65 20 73   insecure file s
04b0: 68 61 72 69 6e 67 3a 0a 09 24 20 66 69 6c 65 64  haring:..$ filed
04c0: 0a 0a 45 78 61 6d 70 6c 65 20 32 2c 20 73 68 61  ..Example 2, sha
04d0: 72 69 6e 67 20 73 65 6e 73 69 74 69 76 65 20 69  ring sensitive i
04e0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 09 23 20 66  nformation:..# f
04f0: 69 6c 65 64 0a 0a 45 78 61 6d 70 6c 65 20 33 2c  iled..Example 3,
0500: 20 73 68 61 72 69 6e 67 20 6f 6e 6c 79 20 61 20   sharing only a 
0510: 73 70 65 63 69 66 69 63 20 64 69 72 65 63 74 6f  specific directo
0520: 72 79 3a 0a 09 23 20 66 69 6c 65 64 20 2d 2d 72  ry:..# filed --r
0530: 6f 6f 74 20 2f 77 77 77 20 2d 2d 75 73 65 72 20  oot /www --user 
0540: 6e 6f 62 6f 64 79 0a 0a 45 78 61 6d 70 6c 65 20  nobody..Example 
0550: 34 2c 20 72 75 6e 6e 69 6e 67 20 61 73 20 61 20  4, running as a 
0560: 64 61 65 6d 6f 6e 3a 0a 09 23 20 66 69 6c 65 64  daemon:..# filed
0570: 20 2d 2d 72 6f 6f 74 20 2f 77 77 77 20 2d 2d 75   --root /www --u
0580: 73 65 72 20 6e 6f 62 6f 64 79 20 2d 2d 64 61 65  ser nobody --dae
0590: 6d 6f 6e 0a 0a 42 75 69 6c 64 20 54 69 6d 65 20  mon..Build Time 
05a0: 43 6f 6e 73 69 64 65 72 61 74 69 6f 6e 73 0a 2d  Considerations.-
05b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05c0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 49 6e 20 67 65 6e 65  --------.In gene
05d0: 72 61 6c 2c 20 69 74 20 69 73 20 62 65 73 74 20  ral, it is best 
05e0: 74 6f 20 6c 65 61 76 65 20 61 6c 6c 20 63 6f 6e  to leave all con
05f0: 66 69 67 75 72 61 74 69 6f 6e 20 74 6f 20 72 75  figuration to ru
0600: 6e 2d 74 69 6d 65 20 73 6f 20 74 68 61 74 20 61  n-time so that a
0610: 0a 63 6f 6d 70 69 6c 65 64 20 62 69 6e 61 72 79  .compiled binary
0620: 20 63 61 6e 20 64 6f 20 61 73 20 6d 75 63 68 20   can do as much 
0630: 61 73 20 70 6f 73 73 69 62 6c 65 20 77 69 74 68  as possible with
0640: 6f 75 74 20 6e 65 65 64 69 6e 67 20 74 6f 20 62  out needing to b
0650: 65 20 72 65 63 6f 6d 70 69 6c 65 64 2e 0a 48 6f  e recompiled..Ho
0660: 77 65 76 65 72 2c 20 74 68 65 72 65 20 61 72 65  wever, there are
0670: 20 73 6f 6d 65 20 74 68 69 6e 67 73 20 74 68 61   some things tha
0680: 74 20 61 72 65 20 62 65 73 74 20 64 6f 6e 65 20  t are best done 
0690: 61 74 20 63 6f 6d 70 69 6c 65 20 74 69 6d 65 20  at compile time 
06a0: 66 6f 72 0a 76 61 72 69 6f 75 73 20 72 65 61 73  for.various reas
06b0: 6f 6e 73 2c 20 65 73 70 65 63 69 61 6c 6c 79 20  ons, especially 
06c0: 69 6e 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 70  in the name of p
06d0: 65 72 66 6f 72 6d 61 6e 63 65 20 6f 72 20 65 78  erformance or ex
06e0: 65 63 75 74 61 62 6c 65 20 73 69 7a 65 2e 0a 0a  ecutable size...
06f0: 66 69 6c 65 64 20 61 64 6d 69 74 73 20 74 68 6f  filed admits tho
0700: 73 65 20 74 72 61 64 65 2d 6f 66 66 73 20 61 72  se trade-offs ar
0710: 65 20 6f 63 63 61 73 69 6f 6e 61 6c 6c 79 20 72  e occasionally r
0720: 65 71 75 69 72 65 64 20 61 6e 64 20 6f 66 66 65  equired and offe
0730: 72 73 20 74 68 65 0a 66 6f 6c 6c 6f 77 69 6e 67  rs the.following
0740: 20 74 75 6e 61 62 6c 65 73 20 74 68 61 74 20 63   tunables that c
0750: 61 6e 20 6f 6e 6c 79 20 62 65 20 74 6f 67 67 6c  an only be toggl
0760: 65 64 20 64 75 72 69 6e 67 20 63 6f 6d 70 69 6c  ed during compil
0770: 65 2d 74 69 6d 65 3a 0a 0a 20 20 20 31 2e 20 4c  e-time:..   1. L
0780: 6f 67 67 69 6e 67 20 28 43 46 4c 41 47 53 2c 20  ogging (CFLAGS, 
0790: 2d 44 46 49 4c 45 44 5f 44 4f 4e 54 5f 4c 4f 47  -DFILED_DONT_LOG
07a0: 3d 31 29 0a 09 49 74 20 69 73 20 70 6f 73 73 69  =1)..It is possi
07b0: 62 6c 65 20 74 6f 20 64 69 73 61 62 6c 65 20 41  ble to disable A
07c0: 4c 4c 20 6c 6f 67 67 69 6e 67 20 66 72 6f 6d 20  LL logging from 
07d0: 66 69 6c 65 64 2e 20 20 57 68 65 6e 20 6c 6f 67  filed.  When log
07e0: 67 69 6e 67 20 69 73 0a 09 63 6f 6d 70 6c 65 74  ging is..complet
07f0: 65 6c 79 20 64 69 73 61 62 6c 65 64 20 69 6e 74  ely disabled int
0800: 65 72 6c 6f 63 6b 73 20 28 6d 75 74 65 78 65 73  erlocks (mutexes
0810: 29 20 66 6f 72 20 74 68 65 20 6c 6f 67 67 69 6e  ) for the loggin
0820: 67 20 70 6f 69 6e 74 65 72 20 61 72 65 0a 09 6e  g pointer are..n
0830: 6f 74 20 65 6e 67 61 67 65 64 20 61 6e 64 20 74  ot engaged and t
0840: 68 65 20 6c 6f 67 67 69 6e 67 20 66 75 6e 63 74  he logging funct
0850: 69 6f 6e 73 20 61 72 65 20 6e 6f 74 20 63 6f 6d  ions are not com
0860: 70 69 6c 65 64 20 61 74 20 61 6c 6c 2e 0a 09 54  piled at all...T
0870: 68 69 73 20 72 65 73 75 6c 74 73 20 69 6e 20 61  his results in a
0880: 20 73 6c 69 67 68 74 6c 79 20 73 6d 61 6c 6c 65   slightly smalle
0890: 72 20 61 6e 64 20 66 61 73 74 65 72 20 62 69 6e  r and faster bin
08a0: 61 72 79 0a 0a 20 20 20 32 2e 20 4b 69 6c 6c 20  ary..   2. Kill 
08b0: 69 64 6c 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73  idle connections
08c0: 20 28 43 46 4c 41 47 53 2c 20 2d 44 46 49 4c 45   (CFLAGS, -DFILE
08d0: 44 5f 44 4f 4e 54 5f 54 49 4d 45 4f 55 54 3d 31  D_DONT_TIMEOUT=1
08e0: 29 0a 20 20 20 20 20 20 20 20 4b 69 6c 6c 69 6e  ).        Killin
08f0: 67 20 69 64 6c 65 20 63 6f 6e 6e 65 63 74 69 6f  g idle connectio
0900: 6e 73 20 72 65 6c 69 65 73 20 68 65 61 76 69 6c  ns relies heavil
0910: 79 20 75 70 6f 6e 20 43 31 31 20 61 74 6f 6d 69  y upon C11 atomi
0920: 63 73 2e 20 20 54 68 69 73 0a 20 20 20 20 20 20  cs.  This.      
0930: 20 20 72 65 71 75 69 72 65 73 20 61 20 72 65 6c    requires a rel
0940: 61 74 69 76 65 6c 79 20 6e 65 77 20 76 65 72 73  atively new vers
0950: 69 6f 6e 20 6f 66 20 47 43 43 20 28 34 2e 39 2b  ion of GCC (4.9+
0960: 29 20 6f 72 20 6f 74 68 65 72 20 43 20 63 6f 6d  ) or other C com
0970: 70 69 6c 65 72 0a 20 20 20 20 20 20 20 20 74 68  piler.        th
0980: 61 74 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 68  at implements th
0990: 69 73 20 61 73 70 65 63 74 20 6f 66 20 43 31 31  is aspect of C11
09a0: 20 61 6e 64 20 73 6f 20 69 74 20 63 61 6e 20 62   and so it can b
09b0: 65 20 64 69 73 61 62 6c 65 64 20 61 74 0a 20 20  e disabled at.  
09c0: 20 20 20 20 20 20 63 6f 6d 70 69 6c 65 20 74 69        compile ti
09d0: 6d 65 20 28 77 68 69 63 68 20 69 73 20 74 68 65  me (which is the
09e0: 20 6f 6e 6c 79 20 74 69 6d 65 20 69 74 20 6d 61   only time it ma
09f0: 6b 65 73 20 73 65 6e 73 65 29 2e 20 20 4f 6e 65  kes sense).  One
0a00: 20 64 61 79 20 61 6e 0a 20 20 20 20 20 20 20 20   day an.        
0a10: 61 6c 74 65 72 6e 61 74 65 20 69 6d 70 6c 65 6d  alternate implem
0a20: 65 6e 74 61 74 69 6f 6e 20 6d 69 67 68 74 20 62  entation might b
0a30: 65 20 70 72 65 73 65 6e 74 20 74 68 61 74 20 75  e present that u
0a40: 73 65 73 20 61 20 6d 75 74 65 78 20 69 6e 73 74  ses a mutex inst
0a50: 65 61 64 0a 20 20 20 20 20 20 20 20 6f 66 20 61  ead.        of a
0a60: 74 6f 6d 69 63 73 20 61 74 20 77 68 69 63 68 20  tomics at which 
0a70: 70 6f 69 6e 74 20 74 68 69 73 20 64 6f 63 75 6d  point this docum
0a80: 65 6e 74 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65  entation will be
0a90: 20 75 70 64 61 74 65 64 2e 0a 0a 20 20 20 33 2e   updated...   3.
0aa0: 20 44 65 62 75 67 67 69 6e 67 20 28 43 46 4c 41   Debugging (CFLA
0ab0: 47 53 2c 20 2d 44 46 49 4c 45 44 5f 44 45 42 55  GS, -DFILED_DEBU
0ac0: 47 3d 31 29 0a 09 54 68 69 73 20 69 73 20 61 6e  G=1)..This is an
0ad0: 20 69 6e 74 65 72 6e 61 6c 20 6f 70 74 69 6f 6e   internal option
0ae0: 20 61 6e 64 20 73 68 6f 75 6c 64 20 6f 6e 6c 79   and should only
0af0: 20 62 65 20 75 73 65 64 20 64 75 72 69 6e 67 20   be used during 
0b00: 64 65 76 65 6c 6f 70 6d 65 6e 74 2e 0a 0a 20 20  development...  
0b10: 20 34 2e 20 44 69 66 66 65 72 69 6e 67 20 48 54   4. Differing HT
0b20: 54 50 20 73 65 6d 61 6e 74 69 63 73 20 28 43 46  TP semantics (CF
0b30: 4c 41 47 53 2c 20 2d 44 46 49 4c 45 44 5f 4e 4f  LAGS, -DFILED_NO
0b40: 4e 42 4c 4f 43 4b 5f 48 54 54 50 3d 31 29 0a 09  NBLOCK_HTTP=1)..
0b50: 49 74 20 69 73 20 70 6f 73 73 69 62 6c 65 20 74  It is possible t
0b60: 68 61 74 20 73 6f 6d 65 20 48 54 54 50 20 63 6c  hat some HTTP cl
0b70: 69 65 6e 74 73 20 6d 61 79 20 6e 6f 74 20 70 72  ients may not pr
0b80: 6f 63 65 73 73 20 74 68 65 20 48 54 54 50 20 73  ocess the HTTP s
0b90: 74 72 65 61 6d 0a 09 62 65 69 6e 67 20 64 65 6c  tream..being del
0ba0: 69 76 65 72 65 64 20 69 66 20 74 68 65 79 20 63  ivered if they c
0bb0: 61 6e 6e 6f 74 20 77 72 69 74 65 20 74 6f 20 74  annot write to t
0bc0: 68 65 20 48 54 54 50 20 73 74 72 65 61 6d 20 69  he HTTP stream i
0bd0: 74 73 65 6c 66 2e 20 20 54 68 69 73 0a 09 68 61  tself.  This..ha
0be0: 73 20 6e 6f 74 20 62 65 65 6e 20 6f 62 73 65 72  s not been obser
0bf0: 76 65 64 20 79 65 74 2c 20 62 75 74 20 69 74 20  ved yet, but it 
0c00: 69 73 20 70 6f 73 73 69 62 6c 65 2e 20 20 49 66  is possible.  If
0c10: 20 74 68 65 73 65 20 73 65 6d 61 6e 74 69 63 73   these semantics
0c20: 20 61 72 65 0a 09 6e 65 65 64 65 64 20 28 61 6e   are..needed (an
0c30: 64 20 74 68 65 79 20 73 68 6f 75 6c 64 20 6e 6f  d they should no
0c40: 74 20 62 65 29 20 74 68 65 6e 20 74 68 65 79 20  t be) then they 
0c50: 63 61 6e 20 62 65 20 65 6e 61 62 6c 65 64 20 77  can be enabled w
0c60: 69 74 68 20 74 68 69 73 0a 09 66 6c 61 67 20 61  ith this..flag a
0c70: 74 20 74 68 65 20 63 6f 73 74 20 6f 66 20 70 65  t the cost of pe
0c80: 72 66 6f 72 6d 61 6e 63 65 2e 0a 0a 20 20 20 35  rformance...   5
0c90: 2e 20 44 69 66 66 65 72 69 6e 67 20 63 68 72 6f  . Differing chro
0ca0: 6f 74 28 29 20 73 65 6d 61 6e 74 69 63 73 20 28  ot() semantics (
0cb0: 43 46 4c 41 47 53 2c 20 2d 44 46 49 4c 45 44 5f  CFLAGS, -DFILED_
0cc0: 46 41 4b 45 5f 43 48 52 4f 4f 54 3d 31 29 0a 20  FAKE_CHROOT=1). 
0cd0: 20 20 20 20 20 20 20 49 6e 20 73 6f 6d 65 20 63         In some c
0ce0: 61 73 65 73 20 69 74 20 69 73 20 64 65 73 69 72  ases it is desir
0cf0: 61 62 6c 65 20 74 6f 20 6d 61 6e 67 6c 65 20 70  able to mangle p
0d00: 61 74 68 73 20 77 69 74 68 20 61 20 70 61 74 68  aths with a path
0d10: 20 70 72 65 66 69 78 0a 20 20 20 20 20 20 20 20   prefix.        
0d20: 72 61 74 68 65 72 20 74 68 61 6e 20 63 61 6c 6c  rather than call
0d30: 20 63 68 72 6f 6f 74 28 29 20 61 74 20 73 74 61   chroot() at sta
0d40: 72 74 75 70 2e 20 20 54 68 69 73 20 69 73 20 6c  rtup.  This is l
0d50: 65 73 73 20 73 65 63 75 72 65 20 61 6e 64 20 73  ess secure and s
0d60: 6c 6f 77 65 72 0a 20 20 20 20 20 20 20 20 61 6e  lower.        an
0d70: 64 20 73 68 6f 75 6c 64 20 62 65 20 67 65 6e 65  d should be gene
0d80: 72 61 6c 6c 79 20 61 76 6f 69 64 65 64 20 2d 2d  rally avoided --
0d90: 20 68 6f 77 65 76 65 72 20 69 74 20 6d 61 79 20   however it may 
0da0: 62 65 20 6e 65 63 65 73 73 61 72 79 20 74 6f 20  be necessary to 
0db0: 64 6f 2e 0a 20 20 20 20 20 20 20 20 49 6e 20 74  do..        In t
0dc0: 68 65 73 65 20 63 61 73 65 73 20 74 68 65 20 65  hese cases the e
0dd0: 78 65 63 75 74 61 62 6c 65 20 6d 61 79 20 62 65  xecutable may be
0de0: 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 20 74   compiled with t
0df0: 68 65 0a 20 20 20 20 20 20 20 20 46 49 4c 45 44  he.        FILED
0e00: 5f 46 41 4b 45 5f 43 48 52 4f 4f 54 20 43 20 70  _FAKE_CHROOT C p
0e10: 72 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 72  reprocessor macr
0e20: 6f 20 64 65 66 69 6e 65 64 20 61 6e 64 20 69 6e  o defined and in
0e30: 73 74 65 61 64 20 6f 66 20 63 61 6c 6c 69 6e 67  stead of calling
0e40: 0a 20 20 20 20 20 20 20 20 63 68 72 6f 6f 74 28  .        chroot(
0e50: 29 20 61 6c 6c 20 48 54 54 50 20 72 65 71 75 65  ) all HTTP reque
0e60: 73 74 73 20 77 69 6c 6c 20 68 61 76 65 20 74 68  sts will have th
0e70: 65 20 72 6f 6f 74 20 73 75 66 66 69 78 20 73 70  e root suffix sp
0e80: 65 63 69 66 69 65 64 20 61 73 20 74 68 65 0a 20  ecified as the. 
0e90: 20 20 20 20 20 20 20 61 72 67 75 6d 65 6e 74 20         argument 
0ea0: 74 6f 20 74 68 65 20 22 2d 72 22 20 6f 72 20 22  to the "-r" or "
0eb0: 2d 2d 72 6f 6f 74 22 20 6f 70 74 69 6f 6e 20 70  --root" option p
0ec0: 72 65 70 65 6e 64 65 64 20 74 6f 20 74 68 65 6d  repended to them
0ed0: 2e 0a 0a 20 20 20 36 2e 20 44 69 66 66 65 72 69  ...   6. Differi
0ee0: 6e 67 20 22 69 6e 64 65 78 2e 68 74 6d 6c 22 20  ng "index.html" 
0ef0: 68 61 6e 64 6c 69 6e 67 20 28 43 46 4c 41 47 53  handling (CFLAGS
0f00: 2c 20 2d 44 46 49 4c 45 44 5f 44 4f 4e 54 5f 52  , -DFILED_DONT_R
0f10: 45 44 49 52 45 43 54 5f 44 49 52 45 43 54 4f 52  EDIRECT_DIRECTOR
0f20: 49 45 53 3d 31 29 0a 20 20 20 20 20 20 20 20 4e  IES=1).        N
0f30: 6f 72 6d 61 6c 6c 79 20 22 66 69 6c 65 64 22 20  ormally "filed" 
0f40: 72 65 64 69 72 65 63 74 73 20 75 73 65 72 73 20  redirects users 
0f50: 77 68 6f 20 72 65 71 75 65 73 74 20 61 20 64 69  who request a di
0f60: 72 65 63 74 6f 72 79 20 74 6f 20 74 68 65 0a 20  rectory to the. 
0f70: 20 20 20 20 20 20 20 69 6e 64 65 78 2e 68 74 6d         index.htm
0f80: 6c 20 66 69 6c 65 20 69 6e 20 74 68 61 74 20 64  l file in that d
0f90: 69 72 65 63 74 6f 72 79 20 73 6f 20 74 68 61 74  irectory so that
0fa0: 20 6e 6f 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63   no memory alloc
0fb0: 61 74 69 6f 6e 73 20 61 72 65 0a 20 20 20 20 20  ations are.     
0fc0: 20 20 20 72 65 71 75 69 72 65 64 3b 20 20 54 68     required;  Th
0fd0: 69 73 20 6f 70 74 69 6f 6e 20 6c 65 74 73 20 74  is option lets t
0fe0: 68 65 20 73 65 72 76 65 72 20 67 65 6e 65 72 61  he server genera
0ff0: 74 65 20 74 68 65 20 6e 65 77 20 70 61 74 68 2e  te the new path.
1000: 0a 0a 20 20 20 37 2e 20 4d 49 4d 45 20 54 79 70  ..   7. MIME Typ
1010: 65 73 20 28 4d 49 4d 45 54 59 50 45 53 29 0a 09  es (MIMETYPES)..
1020: 46 6f 72 20 73 69 6e 67 6c 65 2d 66 69 6c 65 20  For single-file 
1030: 63 6f 6e 76 65 6e 69 65 6e 63 65 20 22 66 69 6c  convenience "fil
1040: 65 64 22 20 63 6f 6d 70 69 6c 65 73 20 74 68 65  ed" compiles the
1050: 20 6d 61 70 70 69 6e 67 20 6f 66 20 66 69 6c 65   mapping of file
1060: 0a 09 65 78 74 65 6e 73 69 6f 6e 73 20 28 74 68  ..extensions (th
1070: 65 20 73 74 72 69 6e 67 20 69 6e 20 74 68 65 20  e string in the 
1080: 66 69 6c 65 6e 61 6d 65 20 66 6f 6c 6c 6f 77 69  filename followi
1090: 6e 67 20 69 74 73 20 6c 61 73 74 20 64 6f 74 20  ng its last dot 
10a0: 28 22 2e 22 29 29 0a 09 69 6e 74 6f 20 74 68 65  ("."))..into the
10b0: 20 65 78 65 63 75 74 61 62 6c 65 2e 20 20 54 68   executable.  Th
10c0: 69 73 20 6d 61 70 70 69 6e 67 20 63 6f 6d 65 73  is mapping comes
10d0: 20 66 72 6f 6d 20 61 20 66 69 6c 65 20 69 6e 20   from a file in 
10e0: 74 68 65 20 66 6f 72 6d 61 74 20 6f 66 0a 09 09  the format of...
10f0: 74 79 70 65 31 20 20 20 74 79 70 65 31 5f 65 78  type1   type1_ex
1100: 74 65 6e 73 69 6f 6e 31 20 74 79 70 65 31 5f 65  tension1 type1_e
1110: 78 74 65 6e 73 69 6f 6e 32 2e 2e 2e 0a 09 09 74  xtension2......t
1120: 79 70 65 32 20 20 20 74 79 70 65 32 5f 65 78 74  ype2   type2_ext
1130: 65 6e 73 69 6f 6e 31 20 74 79 70 65 32 5f 65 78  ension1 type2_ex
1140: 74 65 6e 73 69 6f 6e 32 2e 2e 2e 0a 09 09 2e 2e  tension2........
1150: 2e 0a 09 48 6f 77 65 76 65 72 20 69 74 20 6d 61  ...However it ma
1160: 79 20 6e 6f 74 20 62 65 20 64 65 73 69 72 61 62  y not be desirab
1170: 6c 65 20 74 6f 20 69 6e 63 6c 75 64 65 20 74 68  le to include th
1180: 69 73 20 6d 61 70 70 69 6e 67 2c 20 6f 72 20 69  is mapping, or i
1190: 74 20 6d 61 79 20 62 65 0a 09 64 65 73 69 72 61  t may be..desira
11a0: 62 6c 65 20 74 6f 20 75 73 65 20 79 6f 75 72 20  ble to use your 
11b0: 6f 77 6e 20 6d 61 70 70 69 6e 67 20 72 61 74 68  own mapping rath
11c0: 65 72 20 74 68 61 6e 20 74 68 65 20 64 65 66 61  er than the defa
11d0: 75 6c 74 20 6f 6e 65 2e 20 20 54 68 69 73 0a 09  ult one.  This..
11e0: 63 61 6e 20 62 65 20 64 6f 6e 65 20 62 79 20 73  can be done by s
11f0: 70 65 63 69 66 79 69 6e 67 20 74 68 65 20 4d 49  pecifying the MI
1200: 4d 45 54 59 50 45 53 20 6d 61 63 72 6f 20 74 6f  METYPES macro to
1210: 20 22 6d 61 6b 65 22 2e 20 20 49 66 20 6e 6f 0a   "make".  If no.
1220: 09 6d 61 70 70 69 6e 67 20 69 73 20 64 65 73 69  .mapping is desi
1230: 72 65 64 2c 20 22 2f 64 65 76 2f 6e 75 6c 6c 22  red, "/dev/null"
1240: 20 6d 61 79 20 62 65 20 73 70 65 63 69 66 69 65   may be specifie
1250: 64 2e 0a 0a 4c 6f 67 20 46 69 6c 65 73 0a 2d 2d  d...Log Files.--
1260: 2d 2d 2d 2d 2d 2d 2d 0a 42 65 63 61 75 73 65 20  -------.Because 
1270: 22 66 69 6c 65 64 22 20 72 65 6c 69 65 73 20 6f  "filed" relies o
1280: 6e 20 63 68 72 6f 6f 74 28 32 29 20 61 6e 64 20  n chroot(2) and 
1290: 73 65 74 75 69 64 28 32 29 2c 20 6c 6f 67 20 66  setuid(2), log f
12a0: 69 6c 65 73 20 63 61 6e 6e 6f 74 20 72 65 6c 69  iles cannot reli
12b0: 61 62 6c 79 0a 62 65 20 72 65 2d 6f 70 65 6e 65  ably.be re-opene
12c0: 64 2e 20 20 49 66 20 79 6f 75 20 6e 65 65 64 20  d.  If you need 
12d0: 6c 6f 67 20 72 6f 74 61 74 69 6f 6e 20 74 68 65  log rotation the
12e0: 6e 20 61 20 73 65 63 6f 6e 64 20 70 72 6f 63 65  n a second proce
12f0: 73 73 2c 20 77 68 69 63 68 20 63 61 6e 20 63 6c  ss, which can cl
1300: 6f 73 65 0a 61 6e 64 20 72 65 2d 6f 70 65 6e 20  ose.and re-open 
1310: 6c 6f 67 20 66 69 6c 65 73 2c 20 6d 75 73 74 20  log files, must 
1320: 62 65 20 75 73 65 64 2e 20 20 41 6e 79 20 70 72  be used.  Any pr
1330: 6f 63 65 73 73 20 6d 61 79 20 62 65 20 75 73 65  ocess may be use
1340: 64 20 66 6f 72 20 77 72 69 74 69 6e 67 20 6c 6f  d for writing lo
1350: 67 73 0a 62 75 74 20 69 66 20 74 68 65 20 70 72  gs.but if the pr
1360: 6f 63 65 73 73 20 64 6f 65 73 20 6e 6f 74 20 73  ocess does not s
1370: 75 70 70 6f 72 74 20 6c 6f 67 20 72 6f 74 61 74  upport log rotat
1380: 69 6f 6e 20 74 68 65 6e 20 69 74 20 77 69 6c 6c  ion then it will
1390: 20 6e 6f 74 20 70 72 6f 76 69 64 65 20 74 68 61   not provide tha
13a0: 74 0a 62 65 6e 65 66 69 74 2e 20 20 46 6f 72 20  t.benefit.  For 
13b0: 65 78 61 6d 70 6c 65 2c 20 69 66 20 79 6f 75 20  example, if you 
13c0: 77 69 73 68 20 74 6f 20 77 72 69 74 65 20 6c 6f  wish to write lo
13d0: 67 73 20 74 6f 20 73 79 73 6c 6f 67 64 28 38 29  gs to syslogd(8)
13e0: 20 79 6f 75 20 63 61 6e 20 75 73 65 0a 6c 6f 67   you can use.log
13f0: 67 65 72 28 31 29 2c 20 73 75 63 68 20 61 73 3a  ger(1), such as:
1400: 0a 09 23 20 2e 2f 66 69 6c 65 64 20 2d 2d 72 6f  ..# ./filed --ro
1410: 6f 74 20 2f 77 77 77 20 2d 2d 75 73 65 72 20 6e  ot /www --user n
1420: 6f 62 6f 64 79 20 2d 2d 6c 6f 67 20 27 7c 6c 6f  obody --log '|lo
1430: 67 67 65 72 20 2d 74 20 66 69 6c 65 64 27 20 2d  gger -t filed' -
1440: 2d 64 61 65 6d 6f 6e 0a 0a 54 72 6f 75 62 6c 65  -daemon..Trouble
1450: 73 68 6f 6f 74 69 6e 67 0a 2d 2d 2d 2d 2d 2d 2d  shooting.-------
1460: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 20 20 31 2e 20 49  --------.   1. I
1470: 74 20 77 6f 6e 27 74 20 63 6f 6d 70 69 6c 65 2c  t won't compile,
1480: 20 73 6f 6d 65 74 68 69 6e 67 20 61 62 6f 75 74   something about
1490: 20 73 74 64 61 74 6f 6d 69 63 2e 68 20 6e 6f 74   stdatomic.h not
14a0: 20 66 6f 75 6e 64 20 6f 72 20 5f 41 74 6f 6d 69   found or _Atomi
14b0: 63 20 6e 6f 74 0a 20 20 20 20 20 20 61 20 76 61  c not.      a va
14c0: 6c 69 64 20 74 79 70 65 2e 0a 0a 20 20 20 20 20  lid type...     
14d0: 20 3d 3e 20 54 68 69 73 20 69 73 20 61 20 62 75   => This is a bu
14e0: 67 20 69 6e 20 79 6f 75 72 20 63 6f 6d 70 69 6c  g in your compil
14f0: 65 72 3a 0a 20 20 20 20 20 20 20 20 20 20 20 20  er:.            
1500: 68 74 74 70 73 3a 2f 2f 67 63 63 2e 67 6e 75 2e  https://gcc.gnu.
1510: 6f 72 67 2f 62 75 67 7a 69 6c 6c 61 2f 73 68 6f  org/bugzilla/sho
1520: 77 5f 62 75 67 2e 63 67 69 3f 69 64 3d 35 38 30  w_bug.cgi?id=580
1530: 31 36 0a 0a 20 20 20 20 20 20 20 20 20 47 43 43  16..         GCC
1540: 20 34 2e 37 2e 78 20 61 6e 64 20 34 2e 38 2e 78   4.7.x and 4.8.x
1550: 20 64 65 66 69 6e 65 20 74 68 65 20 6d 61 63 72   define the macr
1560: 6f 20 69 6e 64 69 63 61 74 69 6e 67 20 74 68 61  o indicating tha
1570: 74 20 74 68 65 79 20 68 61 76 65 20 43 31 31 0a  t they have C11.
1580: 20 20 20 20 20 20 20 20 20 73 75 70 70 6f 72 74           support
1590: 20 61 6e 64 20 64 6f 20 6e 6f 74 20 64 65 66 69   and do not defi
15a0: 6e 65 20 74 68 65 20 6d 61 63 72 6f 20 74 68 61  ne the macro tha
15b0: 74 20 43 31 31 20 72 65 71 75 69 72 65 73 20 74  t C11 requires t
15c0: 6f 20 69 6e 64 69 63 61 74 65 0a 20 20 20 20 20  o indicate.     
15d0: 20 20 20 20 74 68 61 74 20 43 31 31 20 61 74 6f      that C11 ato
15e0: 6d 69 63 73 20 61 72 65 20 6e 6f 74 20 61 76 61  mics are not ava
15f0: 69 6c 61 62 6c 65 2e 20 20 54 68 65 79 20 73 68  ilable.  They sh
1600: 6f 75 6c 64 20 64 65 66 69 6e 65 20 74 68 61 74  ould define that
1610: 20 6d 61 63 72 6f 2e 0a 0a 20 20 20 20 20 20 20   macro...       
1620: 20 20 59 6f 75 20 63 61 6e 20 64 69 73 61 62 6c    You can disabl
1630: 65 20 74 68 65 20 66 65 61 74 75 72 65 73 20 69  e the features i
1640: 6e 20 22 66 69 6c 65 64 22 20 74 68 61 74 20 72  n "filed" that r
1650: 65 71 75 69 72 65 20 43 31 31 20 61 74 6f 6d 69  equire C11 atomi
1660: 63 73 20 62 79 0a 20 20 20 20 20 20 20 20 20 64  cs by.         d
1670: 65 66 69 6e 69 6e 67 20 46 49 4c 45 44 5f 44 4f  efining FILED_DO
1680: 4e 54 5f 54 49 4d 45 4f 55 54 20 69 6e 20 74 68  NT_TIMEOUT in th
1690: 65 20 4d 61 6b 65 66 69 6c 65 2e 0a              e Makefile..