Commit graph

205 commits

Author SHA1 Message Date
Tom Cherry
fa3e52c64a init: wait_for_prop shouldn't run in a subcontext
wait_for_prop sets a flag that prevents the action queue from
continuing while otherwise allowing init's main loop to continue
executing.  This cannot be done from a subcontext, so it's moved to
normal init.

All property functions need work in any case, particularly once
property_service is moved out of init.

Bug: 62875318
Test: boot sailfish and see that the previous failure related to this
      is fixed

Change-Id: Ib9e0d0bdbd0ff22ab0e5c3fe6db620700af266c6
2017-10-18 14:42:27 -07:00
Tom Cherry
20acdef816 init: log failures if a service cannot start during class_start
Test: boot system with this logging and see appropriate failures
Change-Id: I312dca89f6215afe05b10b2539258a212a0c1ae2
2017-10-03 13:16:00 -07:00
Tom Cherry
cb0f9bbc85 init: run vendor commands in a separate SELinux context
One of the major aspects of treble is the compartmentalization of system
and vendor components, however init leaves a huge gap here, as vendor
init scripts run in the same context as system init scripts and thus can
access and modify the same properties, files, etc as the system can.

This change is meant to close that gap.  It forks a separate 'subcontext'
init that runs in a different SELinux context with permissions that match
what vendors should have access to.  Commands get sent over a socket to
this 'subcontext' init that then runs them in this SELinux context and
returns the result.

Note that not all commands run in the subcontext; some commands such as
those dealing with services only make sense in the context of the main
init process.

Bug: 62875318
Test: init unit tests, boot bullhead, boot sailfish

Change-Id: Idf4a4ebf98842d27b8627f901f961ab9eb412aee
2017-09-29 13:06:26 -07:00
Tom Cherry
424ed42fb4 Merge "init: add exec_background command" 2017-09-18 21:33:26 +00:00
Tom Cherry
3631c545b8 init: add exec_background command
This command functions similarly to `exec` except that it does not
cause init to halt executing commands until the process has
terminated.  It is useful for launching simple one time background
tasks.

Bug: 65736247
Test: create an exec_background service and see it function properly
Change-Id: I719c8b85479b65201770aedc0a13191303007c11
2017-09-18 12:19:47 -07:00
Tom Cherry
3633a4014a init: fix crash when reboot is triggered by a builtin
Builtin commands may set the sys.powerctl property, which causes
reboot to be immediately processed.  Unfortunately, part of the reboot
processing involves clearing the action queue, so when this scenario
happens, ActionManager::ExecuteOneCommand() can abort due to its state
being unexpectedly changed.

Longer term, the real fix here is to split init and property service.
In this case, the property sets will be sent to property service and
the reboot will only be processed once property service responds back
to init that the property has been set.  Since that will not happen
within the action queue, there will be no risk of failure.

Short term, this change sets a flag in init to shutdown the device
before the next action is run, which defers the shutdown enough to fix
the crash, but continues to prevent any further commands from running.

Bug: 65374456
Test: force bullhead into the repro case and observe that it no longer
      repros

Change-Id: I89c73dad8d7912a845d694b095cab061b8dcc05e
2017-09-15 21:07:41 +00:00
Luis Hector Chavez
9f97f47940 init: Allow clean system shutdown upon SIGTERM
This allows Android to cleanly shutdown when running in a PID namespace
in a way that does not rely on adbd running. This is useful to allow
Android to be running in a container and its lifetime managed by an
OCI-compliant tool.

Bug: 65415372
Test: `kill -TERM 1` as root is correctly dropped.
Test: `kill -TERM 1` from the init PID namespace causes init to cleanly shutdown.
Change-Id: Ia66ebdb436221919081bc4723337c0c7f1e53b09
2017-09-07 10:47:04 -07:00
Wei Wang
02628f3b23 init: add option to read file fully on readahead
Bug: 62413151
Test: boottime, dumpcache
Change-Id: I1a7b69f0619428e4db31c5a7639c5d895c89ecdb
2017-09-01 15:15:51 -07:00
Tom Cherry
7ac013de7e init: support setting rlimits per service
Add a new service option, `rlimit` that allows a given rlimit to be
set for a specific service instead of globally.

Use the same parsing, now allowing text such as 'cpu' or 'rtprio'
instead of relying on the enum value for the `setrlimit` builtin
command as well.

Bug: 63882119
Bug: 64894637

Test: boot bullhead, run a test app that attempts to set its rtprio to
      95, see that the priority set fails normally but passes when
      `rlimit rtprio 99 99` is used as its service option.
      See that this fails when `rlimit rtprio 50 50` is used as well.
Test: new unit tests

Change-Id: I4a13ca20e8529937d8b4bc11718ffaaf77523a52
2017-08-28 10:19:50 -07:00
Tom Cherry
68f2a46145 init: enable error reporting of builtin functions
Enable error reporting when builtin functions fail.  These errors are
now reported with full context including the source file and line
number, e.g.

init: Command 'write /sys/module/subsystem_restart/parameters/enable_debug ${persist.sys.ssr.enable_debug}' action=early-boot (/init.bullhead.rc:84) took 0ms and failed: cannot expand '${persist.sys.ssr.enable_debug}'

There are two small caveats:
1) There are nearly 200 reports of builtins failure due to "No such
   file or directory".  Many of these are due to legacy paths included
   in rootdir/init.rc.  Until they are cleaned up, reporting of these
   failures is disabled.
2) Similarly, symlink is often used to create backwards compatible
   symlinks.  By their very nature, these calls are expected to fail
   on newer systems that do already use the new path.  Due to this,
   failures of symlink due to EEXIST are not reported.

Bug: 38038887
Test: boot bullhead, only see true errors reported from builtins.
Change-Id: I316c13e3adc992cacc6d79ffee987adc8738fca0
2017-08-23 11:05:37 -07:00
Tom Cherry
76af7e6a0c init: log Service failures via Result<T>
Log Service failures via Result<T> such that their context can be
captured when interacting with services through builtin functions.

Test: boot bullhead
Change-Id: I4d99744d64008d4a06a404e3c9817182c6e177bc
2017-08-23 11:05:37 -07:00
Tom Cherry
6de21f1112 init: cleanup environment handling
Init keep its own copy of the environment that it uses for execve when
starting services.  This is unnecessary however as libc already has
functions that mutate the environment and the environment that init
uses is clean for starting services.  This change removes init's copy
of the environment and uses the libc functions instead.

This also makes small clean-up to the way the Service class stores
service specific environment variables.

Test: boot bullhead
Change-Id: I7c98a0b7aac9fa8f195ae33bd6a7515bb56faf78
2017-08-23 10:09:21 -07:00
Tom Cherry
557946e57c init: use Result<T> for builtin functions
We currently throw out the return values from builtin functions and
occasionally log errors with no supporting context.  This change uses
the newly introduced Result<T> class to communicate a successful result
or an error back to callers in order to print an error with clear
context when a builtin fails.

Example:

init: Command 'write /sys/class/leds/vibrator/trigger transient' action=init (/init.rc:245) took 0ms and failed: Unable to write to file '/sys/class/leds/vibrator/trigger': open() failed: No such file or directory

Test: boot bullhead
Merged-In: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
2017-08-14 14:07:39 -07:00
Tom Cherry
11a3aeeae3 init: introduce Result<T> for return values and error handling
init tries to propagate error information up to build context before
logging errors.  This is a good thing, however too often init has the
overly verbose paradigm for error handling, below:

bool CalculateResult(const T& input, U* output, std::string* err)

bool CalculateAndUseResult(const T& input, std::string* err) {
  U output;
  std::string calculate_result_err;
  if (!CalculateResult(input, &output, &calculate_result_err)) {
    *err = "CalculateResult " + input + " failed: " +
      calculate_result_err;
      return false;
  }
  UseResult(output);
  return true;
}

Even more common are functions that return only true/false but also
require passing a std::string* err in order to see the error message.

This change introduces a Result<T> that is use to either hold a
successful return value of type T or to hold an error message as a
std::string.  If the functional only returns success or a failure with
an error message, Result<Success> may be used.  The classes Error and
ErrnoError are used to indicate a failed Result<T>.

A successful Result<T> is constructed implicitly from any type that
can be implicitly converted to T or from the constructor arguments for
T.  This allows you to return a type T directly from a function that
returns Result<T>.

Error and ErrnoError are used to construct a Result<T> has
failed. Each of these classes take an ostream as an input and are
implicitly cast to a Result<T> containing that failure.  ErrnoError()
additionally appends ": " + strerror(errno) to the end of  the failure
string to aid in interacting with C APIs.

The end result is that the above code snippet is turned into the much
clearer example below:

Result<U> CalculateResult(const T& input);

Result<Success> CalculateAndUseResult(const T& input) {
  auto output = CalculateResult(input);
  if (!output) {
    return Error() << "CalculateResult " << input << " failed: "
                   << output.error();
  }
  UseResult(*output);
  return Success();
}

This change also makes this conversion for some of the util.cpp
functions that used the old paradigm.

Test: boot bullhead, init unit tests
Merged-In: I1e7d3a8820a79362245041251057fbeed2f7979b
Change-Id: I1e7d3a8820a79362245041251057fbeed2f7979b
2017-08-14 14:07:30 -07:00
Tom Cherry
0c8d6d2730 init: split security functions out of init.cpp
This change splits out the selinux initialization and supporting
functionality into selinux.cpp and splits the security related
initialization of the rng, etc to security.cpp.  It also provides
additional documentation for SEPolicy loading as this has been
requested by some teams.

It additionally cleans up sehandle and sehandle_prop.  The former is
static within selinux.cpp and new wrapper functions are created around
selabel_lookup*() to better serve the users.  The latter is moved to
property_service.cpp as it is isolated to that file for its usage.

Test: boot bullhead
Merged-In: Idc95d493cebc681fbe686b5160502f36af149f60
Change-Id: Idc95d493cebc681fbe686b5160502f36af149f60
2017-08-14 09:40:01 -07:00
Wei Wang
542aae443f init: Add readahead built-in command
Inspired by ag/2659809/, this CL add readahead built-in command in init
to let files be prefetched into pagecache for faster reading.
Readahead happens in background but due to filesystem limitation it
might take small amount of time in it reading the filesystem metadata
needed to locate the requested blocks. So the command is executed in a
forked process to not block init execution.

Bug: 62413151
Test: boottime, dumpcache
Change-Id: I56c86e2ebc20efda4aa509e6efb736bd1d92baa5
2017-08-11 11:24:08 -07:00
Tom Cherry
7037991f04 init: use unique_fd in builtins.cpp
Test: boot

Change-Id: I09295856dbd0de9436a95a2fe99ab6be156b995f
2017-08-01 14:22:44 -07:00
Tom Cherry
911b9b1d6e init: rename ServiceManager to ServiceList and clean it up
ServiceManager is essentially just a list now that the rest of its
functionality has been moved elsewhere, so the class is renamed
appropriately.

The ServiceList::Find* functions have been cleaned up into a single
smaller interface.
The ServiceList::ForEach functions have been removed in favor of
ServiceList itself being directly iterable.

Test: boot bullhead
Change-Id: Ibd57c103338f03b83d81e8b48ea0e46cd48fd8f0
2017-08-01 11:06:17 -07:00
Tom Cherry
3b81f2d623 init: move exec operations out of ServiceManager
These can be implemented without ServiceManager, so we remove them and
make ServiceManager slightly less of a God class.

Test: boot bullhead
Test: init unit tests
Change-Id: Ia6e546fe5292255412245256f7d230af4ece135f
2017-08-01 11:06:04 -07:00
Tom Cherry
67dee626e0 init: remove Parser singleton and related cleanup
* Remove the Parser singleton (Hooray!)
* Rename parser.* to tokenizer.* as this is actually a tokenizer
* Rename init_parser.* to parser.* as this is a generic parser
* Move contents of init_parser_test.cpp to service_test.cpp as this
  actually is a test of the parsing in MakeExecOneshotService() and
  nothing related to (init_)parser.cpp

Test: boot bullhead
Test: bool sailfish
Test: init unit tests
Change-Id: I4fe39e6483f58ebd3ce5ee715a45dbba0acf5d91
2017-07-27 13:23:32 -07:00
Tom Cherry
ede0d53850 Move Timer from init to libbase
Test: boot bullhead
Test: new libbase unit tests

Change-Id: Ic398a1daa1fe92c10ea7bc1e6ac3f781cee9a5b5
2017-07-10 09:28:24 -07:00
Wei Wang
eeab491efd init: Support custom shutdown actions
We have been seeing panics and errors during shutdown sequence in
some vendor's platform, and it is required to disable error handling
during shutdown.

This CL separates the shutdown request to execute another "shutdown"
trigger at the beginning of shutdown stage. And vendor can use this
trigger to add custom commands needed for shutting down gracefully.

Bug: 38203024
Bug: 62084631
Test: device reboot/shutdown
Change-Id: I3fac4ed59f06667d86e477ee55ed391cf113717f
2017-07-05 14:49:57 -07:00
Tom Cherry
81f5d3ebef init: create android::init:: namespace
With some small fixups along the way

Test: Boot bullhead
Test: init unit tests
Change-Id: I7beaa473cfa9397f845f810557d1631b4a462d6a
2017-06-23 13:21:20 -07:00
Tom Cherry
1c3a53f03c init: cleanup some string usage
1) property_set() takes const std::string& for both of its arguments,
   so stop using .c_str() with its parameters
2) Simplify a few places where StringPrintf() is used to concatenate strings
3) Use std::to_string() instead of StringPrintf() where it's better suited

Test: Boot bullhead
Test: init unit tests
Change-Id: I68ebda0e469f6230c8f9ad3c8d5f9444e0c4fdfd
2017-06-22 17:24:22 -07:00
Tom Cherry
482f36cf74 init: remove restorecon() from util.cpp
restorecon() has become nothing more than a small wrapper around
selinux_android_restore().  This itself isn't super problematic, but
it is an obstacle for compiling util.cpp on the host as that function
is not available on the host.

Bug: 36970783
Test: Boot bullhead
Merged-In: I7e209ece6898f9a0d5eb9e5d5d8155c2f1ba9faf
Change-Id: I7e209ece6898f9a0d5eb9e5d5d8155c2f1ba9faf
2017-05-09 02:25:32 +00:00
Tom Cherry
2cbbe9f7a3 init: do not log directly from read_file() and write_file()
Their callers may be able to add more context, so use an error string
to record the error.

Bug: 38038887
Test: boot bullhead
Test: Init unit tests
Change-Id: I46690d1c66e00a4b15cadc6fd0d6b50e990388c3
2017-05-05 14:37:12 -07:00
Tom Cherry
517e1f17cf init: Check DecodeUid() result and use error string
Check the result of DecodeUid() and return failure when uids/gids are
unable to be decoded.

Also, use an error string instead of logging directly such that more
context can be added when decoding fails.

Bug: 38038887
Test: Boot bullhead
Test: Init unit tests
Change-Id: I84c11aa5a8041bf5d2f754ee9af748344b789b37
2017-05-05 14:37:01 -07:00
Tom Cherry
5a86cb7694 init: use do_exec() for init_user0
Similar to what installkey used to do, init_user0 forks and
synchronously waits for vdc to return.  This is dangerous to do in
init however as init also processes properties from a single thread.

I'm not aware of any specific issues that this is currently causing,
but it's a good preventative measure to match what installkey does and
use do_exec().

Test: Boot bullhead, see that init_user0 still happens
Change-Id: I853c61594fe3d97e91bbb2319ebddf2bbe80d457
2017-05-03 13:25:08 -07:00
Tom Cherry
e7656b7200 ueventd: do not reference init's sehandle
Init exposes a global 'sehandle' that ueventd references as part of
devices.cpp and util.cpp.  This is particularly dangerous in
device_init() in which both uevent and init write to this global.

This change creates a separate local copy for devices.cpp and puts
restrictions on where init.h can be included to make sure the global
used by init is not reference by non-init code.  Future changes to
init should remove this global.

Test: Boot bullhead

Change-Id: Ifefa9e1932e9d647d06cca2618f5c8e5a7a85460
2017-05-01 17:22:49 -07:00
Tom Cherry
ad54d094cd init: create init_tests.cpp
Start a init_tests.cpp file for end-to-end tests that parse small init script
segments and verify that they act as expected.

The first tests ensure that the execution order of event triggers
happens appropriately.

Test: Boot bullhead, run unit tests

Change-Id: Ic446c02605ab796fd41e0596ce1fd381aee80ce0
2017-04-21 18:27:42 -07:00
Tom Cherry
30a6f276fd init: clean up the SectionParser interface and Parser class
Remove the dependency on Action and Service from what should be a
generic Parser class.

Make ActionParser, ImportParser, and ServiceParser take a pointer to
their associated classes instead of accessing them through a
singleton.

Misc fixes to SectionParser Interface:
1) Make SectionParser::ParseLineSection() non-const as it always should
have been.
2) Use Rvalue references where appropriate
3) Remove extra std::string& filename in SectionParser::EndFile()
4) Only have SectionParser::ParseSection() as pure virtual

Document SectionParser.

Make ImportParser report the filename and line number of failed imports.

Make ServiceParser report the filename and line number of duplicated services.

Test: Boot bullhead

Change-Id: I86568a5b375fb4f27f4cb235ed1e37635f01d630
2017-04-21 18:26:40 -07:00
Tom Cherry
98ad32a967 init: handle sys.powerctl immediately
Currently if a process sets the sys.powerctl property, init adds this
property change into the event queue, just like any other property.
The actual logic to shutdown the device is not executed until init
gets to the action associated with the property change.

This is bad for multiple reasons, but explicitly causes deadlock in
the follow scenario:

A service is started with `exec` or `exec_start`
The same service sets sys.powerctl indicating to the system to
shutdown
The same service then waits infinitely

In this case, init doesn't process any further commands until the exec
service completes, including the command to reboot the device.

This change causes init to immediately handle sys.powerctl and reboot
the device regardless of the state of the event queue, wait for exec,
or wait for property conditions.

Bug: 37209359
Bug: 37415192

Test: Init reboots normally
Test: Update verifier can reboot the system
Change-Id: Iff2295aed970840f47e56c4bacc93001b791fa35
2017-04-17 16:40:06 -07:00
Bowgo Tsai
aaf70e77dc fs_mgr: support AVB in fs_mgr_update_verity_state()
fs_mgr_update_verity_state() is invoked by 'verity_update_state' in
init.rc. It will then set property "partition.system.verified" and
"partition.vendor.verified" to verify_mode. We should support this for
AVB as well.

Also change the order of static libs in init to fix the build error
after this change:
  system/extras/ext4_utils/ext4_crypt.cpp:69: error: undefined reference to 'property_get'

Bug: 35416769
Test: Mount /system and /vendor with vboot 2.0 (AVB), check the following properties exist.
      - [partition.system.verified]: [2]
      - [partition.vendor.verified]: [2]
Test: Mount /system and /vendor with vboot 1.0, check the following properties exist.
      - [partition.system.verified]: [0]
      - [partition.vendor.verified]: [0]

Change-Id: I4328d66a8cb93f26e7960e620a0b2292d5f15900
2017-04-14 12:10:49 +08:00
Dmitri Plotnikov
00e1c4f330 Passing additional parameter to powerctl
Test: adb reboot recovery,foo and verify that the parameter reaches bootloader
Change-Id: I9690cf96cf9730e5324b9f5310c3d0341fe25fe2
2017-04-12 14:38:23 -07:00
Tom Cherry
f57c0bfab2 init: clean up more headers
We don't need everyone including <sys/system_properties.h>

Test: boot bullhead
Change-Id: I73d507e4f273678eaf15947725741e1e3b966cc6
2017-04-07 13:49:12 -07:00
Tom Cherry
3f5eaae526 init: more header cleanup
Remove includes of "log.h" that really want <android-base/logging.h>
Fix header include order
Remove headers included in .cpp files that their associated .h already includes
Remove some unused headers

Test: boot bullhead
Change-Id: I2b415adfe86a5c8bbe4fb1ebc53c7b0ee2253824
2017-04-06 18:06:34 -07:00
Yongqin Liu
dbe88e7953 init: use read_file and write_file to implement do_copy builtin
this will make the implementation more cleaner,
and has error message output when failed on some operations

also add the O_TRUNC flag explicitly for the open function
called in write_file.

And add more test on read_file and write_file functions

Bug: 36726045
Test: manual with hikey
Test: boot and init tests on bullhead
Test: cast with fugu, per b/36726045
Merged-In: If3c30a2fff58cfece2fcd27e69c30382146e6808

Change-Id: If3c30a2fff58cfece2fcd27e69c30382146e6808
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2017-04-04 06:21:29 +00:00
Tom Cherry
53089aa25c init: Use std::string for write_file()
The content parameter of write_file() previously took a char* that was
then converted to a std::string in WriteStringToFd().  One unfortunate
effect of this, is that it is impossible to write data that contains
'\0' within it, as the new string will only contain characters up
until the '\0'.

This changes write_file() to take an std::string, such that
std::string::size() is used to determine the length of the string,
allowing it to contain null characters.

Also change the path parameter of read_file() and write_file() for
consistency.

Lastly, add a test for handling strings with '\0' in them.

Bug: 36726045
Test: Boot bullhead, run unit tests
Change-Id: Idad60e4228ee2de741ab3ab6a4917065b5e63cd8
2017-04-03 16:41:22 -07:00
Tom Cherry
cf29755e28 Merge "Make init builtin command installkey respect property updates" 2017-03-31 16:41:02 +00:00
Wonsik Kim
3428d0c2c0 Merge "Revert "init: use read_file and write_file to implement do_copy builtin"" 2017-03-31 00:22:00 +00:00
Wonsik Kim
395e29472f Revert "init: use read_file and write_file to implement do_copy builtin"
This reverts commit 82bac0de6d.

Change-Id: Ibfdf453bd85ba4fcd1948b78bd22e639a883653e
2017-03-31 00:18:13 +00:00
Janis Danisevskis
9cc51728af Make init builtin command installkey respect property updates
init used to block on installkey such that it was unable to
process property events. This lead to a deadlock by which
the Keymaster HAL would wait indefinitely for the
hwservicemanager.ready=true. 

This fixes the issue by implementing the builtin in terms of 
do_exec, which allows init to stay responsive to properties 
while waiting for the child to terminate.

Bug: 36278706
Test: Add a 3s delay into hwservicemanager before it sets the property
      hwservicemanager.ready and the device still boots.

Change-Id: Iaefd31156ca01f3a44b4f85a8bf78beee8dfe224
2017-03-30 00:11:48 +00:00
Treehugger Robot
8772b3686e Merge changes from topic 'exec-start-update-verifier'
* changes:
  init.rc: launch update_verifier with exec_start
  init: add exec_start command
2017-03-29 18:39:32 +00:00
Tom Cherry
ccf23537ee init: replace property_get with its android::base equivalent
Slowly try to decouple property_service.cpp from the rest of init.

Test: Boot bullhead
Change-Id: I267ae0b057bca0bf657b97cb8bfbb18199282729
2017-03-29 10:07:54 -07:00
Treehugger Robot
20e43a2f2c Merge "init: remove unused cutils includes" 2017-03-29 01:27:19 +00:00
Tom Cherry
1ec1bd918c init: remove unused cutils includes
Test: Boot bullhead
Change-Id: I629f9c3863f00fa38f87a68442c2380d28764718
2017-03-28 16:22:33 -07:00
Tom Cherry
b27004aa05 init: add exec_start command
Exec services may also want to set other service flags such as
priority.  Instead of expanding the exec syntax to handle this, create
a new command, exec_start, that will treat an existing service
definition as an exec service.  The new exec_start command will start
the service then halt init from executing further commands until the
service has exited.

This change additionally encapsulates the waiting_for_exec logic into
ServiceManager and removes the ambiguous 'bool' return value from
Reap() which previously indicated if a Reaped service was an exec
service or not.

Bug: 36511808
Bug: 36102163
Test: Bullhead boots, services run with exec_start as they do exec.

Change-Id: I44f775cf1c1dd81d5c715f44fdc150c651a2c80a
2017-03-27 17:41:27 -07:00
Steven Moreland
2b63d54af8 init: add class_restart
Bug: 34093663
Test: hwservicemanager `onrestart class_restart hal` works
Change-Id: Ie1e4daab2b7b4c6c714d4e3d05afa2d86d6233df
2017-03-27 13:52:47 -07:00
Treehugger Robot
7f0d15a6f2 Merge "init: use read_file and write_file to implement do_copy builtin" 2017-03-24 02:26:14 +00:00
Yongqin Liu
82bac0de6d init: use read_file and write_file to implement do_copy builtin
this will make the implementation more cleaner,
and has error message output when failed on some operations

also add the O_TRUNC flag explicitly for the open function
called in write_file.

And add more test on read_file and write_file functions

Test: manual with hikey

Change-Id: Ifc1086a20e85db6980b497b1150a8a7952e672d6
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2017-03-24 08:34:25 +08:00