2016-03-03 23:09:25 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
nsjail - CLONE_NEWUTS routines
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
Copyright 2014 Google Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uts.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-02-11 00:49:15 +08:00
|
|
|
#include "logs.h"
|
2018-02-10 00:59:51 +08:00
|
|
|
|
|
|
|
namespace uts {
|
2016-03-03 23:09:25 +08:00
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
bool initNs(nsjconf_t* nsjconf) {
|
2018-02-12 22:17:33 +08:00
|
|
|
if (!nsjconf->clone_newuts) {
|
2016-03-04 03:11:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-10 11:10:18 +08:00
|
|
|
LOG_D("Setting hostname to '%s'", nsjconf->hostname.c_str());
|
|
|
|
if (sethostname(nsjconf->hostname.c_str(), strlen(nsjconf->hostname.c_str())) == -1) {
|
|
|
|
PLOG_E("sethostname('%s')", nsjconf->hostname.c_str());
|
2016-03-03 23:09:25 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-10 00:59:51 +08:00
|
|
|
|
|
|
|
} // namespace uts
|